Reputation: 3335
FLT_MAX
has a bit pattern of 01111111011111111111111111111111
.
If I understand correctly, such a bit pattern should represent 1.111...1 * 2^128
(with twenty-three 1's after the decimal). However, the actual value of FLT_MAX
is just 1.0 * 2^128
. What's going on here?
Upvotes: 1
Views: 1527
Reputation: 183948
Your exponent is wrong, it's 1.111...1 * 2^127 = 2^128 - 2^104
. That is pretty close (relatively) to 2^128
, and you need to print it out with more than default precision in C or C++ to see the difference (note, as a float
- if that is an IEEE754 32-bit float
- 2^128
is infinity, so you need a double
).
The bit pattern yields
0 11111110 11111111111111111111111
^ ^ ^
sign exponent mantissa
254-127 2 - 2^(-23)
Printing the full values:
340282346638528859811704183484516925440.0 // FLT_MAX
340282366920938463463374607431768211456.0 // 2^128
you can see the difference at the eighth digit.
Upvotes: 3