Why number are (not) representable in double precision IEEE754?

邮差的信 提交于 2020-01-06 21:11:00

问题


I am confused on IEEE754 double precision, I consider two questions:
1. Why each number from interval -254, -254+2, -254+4...254 is representable ?

2. Why 254+2 is not representable ?

Can you help me ? I understand way of working IEEE754 - however, I have a problem with seeing it.


回答1:


There are 53 bits in the significand (or mantissa) of an IEEE 754 double. −254 can be exactly represented, as

mantissa: 1.00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00 (bin)
exponent: 54
sign:     1

Now let's forget the sign bit for a moment. It is irrelevant for this explanation. So assume we have +254.

With this exponent, the lowest -- rightmost -- bit of the significand has the value 2-52 * 254 = 4. So 254 + 4 is encoded as:

mantissa: 1.00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 01 (bin)
exponent: 54                                                             ^
                                                                lowest bit

But there is no value inbetween. So you cannot encode 254 + 2.

Why is this not a problem for −254 + 2? Because that is the same as −(254 − 2), and that is represented as:

mantissa: 1.11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 11
exponent: 53 !!
sign:     1

And the exponent 53 means you have steps of 2-52 * 253 = 2. The next value toward 0 is then:

mantissa: 1.11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 10
exponent: 53
sign:     1

which is −254 + 4, or actually −(254 − 4). And you can go on like that until you reach −253.



来源:https://stackoverflow.com/questions/39291410/why-number-are-not-representable-in-double-precision-ieee754

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!