Question

What is the smallest integer after which only integers can be represented by IEEE 754 (single/double)?

My guess is that it occurs when the exponent is 254 (11111110b single). With that, no matter what one puts in the mantissa the number will be an integer. I just want to confirm that and what would be the equivalence in powers of 2.

Était-ce utile?

La solution

Presuming that “after” refers to numbers with greater magnitude and not later in time, 223 for 32-bit binary floating-point and 252 for 64-bit binary floating-point. (These are float and double in the most common programming language implementations with those type names.)

This is because the significands of the 32-bit and 64-bit formats have 24 and 53 bits, respectively. So, in the 32-bit format, if the high bit is scaled to 222 by the exponent, the low bit would be 2–1 (from 22 to –1, inclusive, is 24 positions). Since the significand contains a bit scaled to a non-integer value, the complete represented value could be a non-integer. If the high bit is scaled to 223 or greater, then the low bit has value at least 20.

So, if an integer is less than 223, it is at most 223–1, which means its high significand bit is scaled to 222, so the low bit is 2–1. Indeed, 223–½ is exactly representable as a float.

The same reasoning applies to double.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top