What’s the difference between a single precision and double precision floating point operation?

0. 64-bits CPU

如果说一个 CPU 是 64 位机,通常意味着,其具有 64 位的通用寄存器(general purpose register)以及内存地址空间的大小(memory address size),这与最终执行的数学运算,是单精度还是双精度,没有关系。

1. 单精度

S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1      8 9                    31
  • 第 1 个 bit 位,表示的是符号位,S;
  • 中间 8 位,表示指数部分,E;
  • 末尾的 23 位,则表示小数部分,F;
0 00000000 00000000000000000000000 = 0
1 00000000 00000000000000000000000 = -0

0 11111111 00000000000000000000000 = Infinity
1 11111111 00000000000000000000000 = -Infinity

0 11111111 00000100000000000000000 = NaN
1 11111111 00100010001001010101010 = NaN

0 10000000 00000000000000000000000 = +1 * 2**(128-127) * 1.0 = 2
0 10000001 10100000000000000000000 = +1 * 2**(129-127) * 1.101 = 6.5
1 10000001 10100000000000000000000 = -1 * 2**(129-127) * 1.101 = -6.5

0 00000001 00000000000000000000000 = +1 * 2**(1-127) * 1.0 = 2**(-126)
0 00000000 10000000000000000000000 = +1 * 2**(-126) * 0.1 = 2**(-127) 
0 00000000 00000000000000000000001 = +1 * 2**(-126) * 
                                     0.00000000000000000000001 = 
                                     2**(-149)  (Smallest positive value)

2. 双精度

S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
0 1        11 12                                                63
  • 1 位;
  • 11 位;
  • 52 位;
posted on 2016-11-22 22:13  未雨愁眸  阅读(1045)  评论(0编辑  收藏  举报