本页使用了标题或全文手工转换

雙精度浮點數

维基百科,自由的百科全书
跳到导航 跳到搜索

雙精度浮點數(double)是计算机使用的一種資料型別。比起單精度浮點數雙精度浮點數(double)使用 64 位(8字节) 來儲存一個浮點數。 它可以表示二進位制的53位有效數字,其可以表示的数字的绝对值范围为

格式[编辑]

sign bit(符號):用來表示正負號

exponent(指數):用來表示次方數

mantissa(尾數):用來表示精確度

General double precision float.png

符号[编辑]

0代表數值為正,1代表數值為負。

指数[编辑]

使用二補數表示法,範圍為-1024(0x400)到+1023(0x3ff),但有四個例外:

  • 指數為+1023(0x3ff),尾數的每個位數都是1,符號為0,表示正無窮大
  • 指數為+1023(0x3ff),尾數的每個位數都是1,符號為1,表示負無窮大
  • 指數為-1024(0x400),尾數的每個位數都是0,符號為0,表示0
  • 指數為-1024(0x400),尾數的每個位數都是0,符號為1,表示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

参考文献[编辑]

參閱[编辑]