previous | start | next

Next Float!

For integers, there is a uniquely defined next integer with no integers in between. Next(5) is 6, Next(-3) is -2.

What is Next(0x7fff ffff)? or in decimal, Next(2147483647)?

Next(0x7fffffff) is 0x80000000 or equivalently in decimal,

Next(2147483647) is -2147483648.

What about real numbers? Is there a next real number after 8.0?

No, but given a C float value, there is a next larger float value (except for the special values).

The binary representation of float 8.0 is:

s     e                  f
0 10000010 000 0000 0000 0000 0000 0000
   

The next float value is:

s     e                  f
0 10000010 000 0000 0000 0000 0000 0001
   

Which is exactly

      8.000000095367431640625
   

So this means numbers strictly between 8.0 and 8.000000095367431640625 cannot be represented exactly as a C float (32 bit).



previous | start | next