Re: sizeof float in Xcode debugger
Re: sizeof float in Xcode debugger
- Subject: Re: sizeof float in Xcode debugger
- From: Andy Lee <email@hidden>
- Date: Tue, 24 Jun 2008 10:31:48 -0400
On Jun 24, 2008, at 9:47 AM, email@hidden wrote:
On Jun 24, 2008, at 9:02 AM, Andy Lee wrote:
I'm not too familiar with floating point but from this it seems the
exponent is base 2, not base 10:
<http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point_representation.html
>
This would add more decimal digits of precision.
I wonder if it works to look at it another way? Consider the
sequence 0.5, 0.25, 0.125, 0.0625, etc. Each bit of binary
precision adds a digit of decimal precision, because halving that
last 25 results in a 125. It seems to me you'd be able to express
a number with 24 decimal digits after the decimal point with 24
bits of mantissa. Is my math off here?
Yes, your math is off here.
Hm, you're right, what I said didn't make sense.
I suspect we're getting off topic, but Michael is correct that you
get about 7 significant decimal digits with single precision. You
get about 15 significant decimal digits with double precision. You
should ignore any number of significant digits beyond that displayed
in any program that uses the IEEE standard floating/double precision
formats. And even worse, because of the limited number of values
that can be represented exactly (e.g., you can't represent 0.1
exactly using the IEEE format), you will get round-off errors
meaning your answer may not even be accurate to 7 or 15 digits
depending on your calculations.
I think I am also using the word "precision" incorrectly.
I know not all decimal fractions can be expressed in a finite number
of binary digits, and that is why we need to limit the number of
decimal digits we trust in printed output. But every binary fraction
*can* be expressed exactly in a finite number of decimal digits.
Suppose a float has a mantissa of 1 and an exponent of -64 (assuming
we have a signed seven-bit exponent). If I'm correct that the
exponent is base 2, then this float exactly represents the decimal
number .00000000000000000005. It seems to me you might not trust a
float to represent the number you meant, but it does represent *some*
exact number, and you might be interested in what that exact number is
up to more than 7 digits.
Let me know if I'm off-base here... so to speak. If you think off-
list would be more appropriate, that's fine with me.
And again, what the OP observed may not be a discrepancy at all in
floating-point representation.
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden