how IEEE-754 floating point numbers work

北战南征 提交于 2019-11-28 09:19:16

Think first in terms of decimal (base 10): 643.72 is:

  • (6 * 102) +
  • (4 * 101) +
  • (3 * 100) +
  • (7 * 10-1) +
  • (2 * 10-2)

or 600 + 40 + 3 + 7/10 + 2/100.

That's because n0 is always 1, n-1 is the same as 1/n (for a specific case) and n-m is identical to 1/nm (for more general case).

Similarly, the binary number 1.1 is:

  • (1 * 20) +
  • (1 * 2-1)

with 20 being one and 2-1 being one-half.

In decimal, the numbers to the left of the decimal point have multipliers 1, 10, 100 and so on heading left from the decimal point, and 1/10, 1/100, 1/1000 heading right (i.e., 102, 101, 100, decimal point, 10-1, 10-2, ...).

In base-2, the numbers to the left of the binary point have multipliers 1, 2, 4, 8, 16 and so on heading left. The numbers to the right have multipliers 1/2, 1/4, 1/8 and so on heading right.

So, for example, the binary number:

101.00101
| |   | |
| |   | +- 1/32
| |   +---  1/8
| +-------    1
+---------    4

is equivalent to:

4 + 1 + 1/8 + 1/32

or:

    5
5  --
   32

1.1 in binary is 1 + .5 = 1.5

The mantissa is essentially shifted by the exponent.

3 in binary is 0011
3>>1 in binary, equal to 3/2, is 0001.1

You want to read this - IEEE 754-1985

The actual standard is here

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