Excerpt from a book:
A float value consists of a 24-bit
signed mantissa and an 8-bit signed
exponent. The precision is approximately seven decimal digits.
Values
range from
-3.402823 × 10^38 to 3.402823 × 10^38
How to calculate this range? Can someone explain the binary arithmetic?
I would definitely read the article to which Richard points. But if you need a simpler explanation, I hope this helps:
Basically, as you said, there is 1 sign bit, 8 bits for exponent, and 23 for fraction.
Then, using this equation (from Wikipedia)
N = (1 - 2s) * 2^(x-127) * (1 + m*2^-23)where
sis the sign bit,xis the exponent (minus the 127 bias), andmis the fractional part treated as a whole number (the equation above transforms the whole number into the appropriate fraction value).Note, that the exponent value of
0xFFis reserved to represent infinity. So the largest exponent of a real value is0xFE.you see that the maximum value is
N = (1 - 2*0) * 2^(254-127) * (1 + (2^23 - 1) * 2^-23)N = 1 * 2^127 * 1.999999N = 3.4 x 10^34The minimum value would be the same but with the sign bit set, which would simply negate the value to give you
-3.4 X 10^34.Q.E.D.