Which is the first integer that an IEEE 754 float is incapable of representing exactly?

2mantissa bits + 1 + 1

The +1 in the exponent (mantissa bits + 1) is because, if the mantissa contains abcdef... the number it represents is actually 1.abcdef... × 2^e, providing an extra implicit bit of precision.

Therefore, the first integer that cannot be accurately represented and will be rounded is:

  • For 32-bit floats, 16,777,217 (224 + 1).
  • For 64-bit floats, 9,007,199,254,740,993 (253 + 1).

Here’s an example in CPython 3.10, which uses 64-bit floats:

>>> 9007199254740993.0
9007199254740992.0

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)