双精度浮点数(英语:Double-precision floating-point)是计算机使用的一种资料型别。比起单精度浮点数仅有 32 位元(4字节),双精度浮点数使用 64 位元(8字节) 来储存一个浮点数[1]。 它可以表示二进位制的53位有效数字,其可以表示的数字的绝对值范围为

格式

  • sign bit(符号):用来表示正负号
  • exponent(指数):用来表示次方数
  • mantissa(尾数):用来表示精确度

Thumb

符号

0代表数值为正,1代表数值为负。

指数

共有11个位元 , 使用“偏移表示法英语Exponent bias”, 有2个例外分别为

  1. “11个位元皆为0”
  2. “11个位元皆为1”

并且以1023为偏移标准,表示实际指数为0,因此指数范围为 -1022 到 +1023:

指数 000167ff16 具有特殊意义:

000000000002 = 00016当尾数为0时为±0,尾数不为0时为非正规形式的浮点数

111111111112 = 7ff16当尾数为0时为∞,尾数不为0时为NaN

尾数

二进位的“科学记号”,数字被表示为:

二进位的“科学记号”(a×2n)的a的范围是大于等于1而小于2,例如:

  • 二进位制的 可以规格化为 ,储存时尾数只需要储存1101即可。
  • 二进位制的 可以规格化为 ,储存时尾数只需要储存10011即可。

小结

根据以上的叙述,一个双精度浮点数所代表的数值为:

例子

0 01111111111 00000000000000000000000000000000000000000000000000002 ≙ 3FF0 0000 0000 000016 ≙ +20 × 1 = 1
0 01111111111 00000000000000000000000000000000000000000000000000012 ≙ 3FF0 0000 0000 000116 ≙ +20 × (1 + 2−52) ≈ 1.0000000000000002, the smallest number > 1
0 01111111111 00000000000000000000000000000000000000000000000000102 ≙ 3FF0 0000 0000 000216 ≙ +20 × (1 + 2−51) ≈ 1.0000000000000004
0 10000000000 00000000000000000000000000000000000000000000000000002 ≙ 4000 0000 0000 000016 ≙ +21 × 1 = 2
1 10000000000 00000000000000000000000000000000000000000000000000002 ≙ C000 0000 0000 000016 ≙ −21 × 1 = −2
0 10000000000 10000000000000000000000000000000000000000000000000002 ≙ 4008 0000 0000 000016 ≙ +21 × 1.12 = 112 = 3
0 10000000001 00000000000000000000000000000000000000000000000000002 ≙ 4010 0000 0000 000016 ≙ +22 × 1 = 1002 = 4
0 10000000001 01000000000000000000000000000000000000000000000000002 ≙ 4014 0000 0000 000016 ≙ +22 × 1.012 = 1012 = 5
0 10000000001 10000000000000000000000000000000000000000000000000002 ≙ 4018 0000 0000 000016 ≙ +22 × 1.12 = 1102 = 6
0 10000000011 01110000000000000000000000000000000000000000000000002 ≙ 4037 0000 0000 000016 ≙ +24 × 1.01112 = 101112 = 23
0 01111111000 10000000000000000000000000000000000000000000000000002 ≙ 3F88 0000 0000 000016 ≙ +2−7 × 1.12 = 0.000000112 = 0.01171875 (3/256)
0 00000000000 00000000000000000000000000000000000000000000000000012 ≙ 0000 0000 0000 000116 ≙ +2−1022 × 2−52 = 2−1074
≈ 4.9406564584124654 × 10−324 (Min. subnormal positive double)
0 00000000000 11111111111111111111111111111111111111111111111111112 ≙ 000F FFFF FFFF FFFF16 ≙ +2−1022 × (1 − 2−52)
≈ 2.2250738585072009 × 10−308 (Max. subnormal double)
0 00000000001 00000000000000000000000000000000000000000000000000002 ≙ 0010 0000 0000 000016 ≙ +2−1022 × 1
≈ 2.2250738585072014 × 10−308 (Min. normal positive double)
0 11111111110 11111111111111111111111111111111111111111111111111112 ≙ 7FEF FFFF FFFF FFFF16 ≙ +21023 × (1 + (1 − 2−52))
≈ 1.7976931348623157 × 10308 (Max. Double)
0 00000000000 00000000000000000000000000000000000000000000000000002 ≙ 0000 0000 0000 000016 ≙ +0
1 00000000000 00000000000000000000000000000000000000000000000000002 ≙ 8000 0000 0000 000016 ≙ −0
0 11111111111 00000000000000000000000000000000000000000000000000002 ≙ 7FF0 0000 0000 000016 ≙ +∞ (positive infinity)
1 11111111111 00000000000000000000000000000000000000000000000000002 ≙ FFF0 0000 0000 000016 ≙ −∞ (negative infinity)
0 11111111111 00000000000000000000000000000000000000000000000000012 ≙ 7FF0 0000 0000 000116 ≙ NaN (sNaN on most processors, such as x86 and ARM)
0 11111111111 10000000000000000000000000000000000000000000000000012 ≙ 7FF8 0000 0000 000116 ≙ NaN (qNaN on most processors, such as x86 and ARM)
0 11111111111 11111111111111111111111111111111111111111111111111112 ≙ 7FFF FFFF FFFF FFFF16 ≙ NaN (an alternative encoding of NaN)
0 01111111101 01010101010101010101010101010101010101010101010101012
= 3fd5 5555 5555 555516 ≙ +2−2 × (1 + 2−2 + 2−4 + ... + 2−52)
1/3
0 10000000000 10010010000111111011010101000100010000101101000110002
= 4009 21fb 5444 2d1816 ≈ pi

参考文献

参阅

Wikiwand in your browser!

Seamless Wikipedia browsing. On steroids.

Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.

Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.