CSAPP 3ed 练习题 2.49 IEEE 浮点精度

CSAPP 3ed Practice Problem 2.49 IEEE Floating-Point Precision

For a floating-point format with an n-bit fraction, give a formula for the smallest positive integer that cannot be represented exactly (because it would require an (n + 1)-bit fraction to be exact). Assume the exponent field size k is large enough that the range of representable exponents does not provide a limitation for this problem.

书上给出的解是2^(n + 1) + 1,但是没有给出任何解释。有人能解释一下我们是如何推导出这个公式的吗?谢谢。

考虑具有 23 位精度分数的 32-bit floating-point IEEE 表示。

24位整数1111111111111111111111112 = 224 - 1可以精确表示,因为有足够的位(即使最重要的是 implicit).

加 1,我们有 10000000000000000000000002 = 224。没问题,即使它是 25 位数,因为它是 2 的幂。

下一个,10000000000000000000000012 = 224 + 1,虽然,可以无法准确表示,因为表示的小数部分没有足够的位。