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

前端 未结 2 731
难免孤独
难免孤独 2020-11-22 01:57

For clarity, if I\'m using a language that implements IEE 754 floats and I declare:

float f0 = 0.f;
float f1 = 1.f;

...and then print them

2条回答
  •  情书的邮戳
    2020-11-22 02:37

    The largest value representable by an n bit integer is 2n-1. As noted above, a float has 24 bits of precision in the significand which would seem to imply that 224 wouldn't fit.

    However.

    Powers of 2 within the range of the exponent are exactly representable as 1.0×2n, so 224 can fit and consequently the first unrepresentable integer for float is 224+1. As noted above. Again.

提交回复
热议问题