Understanding floating point representation errors; what's wrong with my thinking?

后端 未结 5 1675
再見小時候
再見小時候 2020-12-11 06:15

I\'m having some trouble understanding why some figures can\'t be represented with floating point number.

As we know, a normal float would have sign bit, exponent,

5条回答
  •  一向
    一向 (楼主)
    2020-12-11 07:04

    Each floating-point number in the IEEE 754 standard is, in effect, some integer multiplied by some integer power of two. E.g., 3 is represented by 3 * 20, 96 is represented by 3 * 23, and 3/16 is represented by 3 * 2-4.

    There are no integers x and y such that .1 = x * 2y, therefore .1 cannot be exactly represented by a floating-point number. Proof: If .1 = x * 2y, then 10x = 2-y. 2-y is clearly positive, so x is positive. It is also an integer, so 10x is divisible by 10, so it is divisible by 5. Therefore 2-y is a power of two that is divisible by 5, which is clearly impossible.

提交回复
热议问题