What range of numbers can be represented in a 16-, 32- and 64-bit IEEE-754 systems?

前端 未结 7 1439
天涯浪人
天涯浪人 2020-11-22 12:20

I know a little bit about how floating-point numbers are represented, but not enough, I\'m afraid.

The general question is:

For a given preci

7条回答
  •  死守一世寂寞
    2020-11-22 12:35

    For floating-point integers (I'll give my answer in terms of IEEE double-precision), every integer between 1 and 2^53 is exactly representable. Beyond 2^53, integers that are exactly representable are spaced apart by increasing powers of two. For example:

    • Every 2nd integer between 2^53 + 2 and 2^54 can be represented exactly.
    • Every 4th integer between 2^54 + 4 and 2^55 can be represented exactly.
    • Every 8th integer between 2^55 + 8 and 2^56 can be represented exactly.
    • Every 16th integer between 2^56 + 16 and 2^57 can be represented exactly.
    • Every 32nd integer between 2^57 + 32 and 2^58 can be represented exactly.
    • Every 64th integer between 2^58 + 64 and 2^59 can be represented exactly.
    • Every 128th integer between 2^59 + 128 and 2^60 can be represented exactly.
    • Every 256th integer between 2^60 + 256 and 2^61 can be represented exactly.
    • Every 512th integer between 2^61 + 512 and 2^62 can be represented exactly. . . .

    Integers that are not exactly representable are rounded to the nearest representable integer, so the worst case rounding is 1/2 the spacing between representable integers.

提交回复
热议问题