双精度浮点数
双精度浮点数 | |
---|---|
术语名称 | 双精度浮点数 |
英语名称 | double-precision floating-point type |
别名 | double-precision floating-point format, 双精度浮点型, 双精浮点, double, float64, FP64, binary64, 64位浮点数, 64-bit floating-point format |
双精度浮点数/双精度浮点型(double-precision floating-point number)是浮点型中长 64 二进制位的数据类型,符合 IEEE 754 中 binary64 类型的格式(IEEE 754-1985 旧称 double)。根据长度,称为 float64 或 binary64 ,有时也称 double 。是通用计算中最常用的浮点类型之一。
双精度浮点数在科学计算、计算机图形学、嵌入式系统中广泛应用,传统上一般用在单精度浮点数精度不足的场景下,现在一般对这一点性能差别要求不高,在大部分情况下可以直接使用。精度高于单精度类型,代价是计算效率更低,但是除了对时间要求极高的场景,一般影响可以忽略。
定义
双精度浮点数(double-precision floating-point type)或 float64 、 FP64 、 binary64 ,指长度为 64 位、符合 IEEE 754 中 binary64 类型浮点格式的浮点类型。
其中浮点数的 64 位包括符号位 1 位、阶码 11 位、尾数 52 位。
范围
阶码 11 位,因此阶码偏移量为 [math]\displaystyle{ b=2^{11-1}-1=1023 }[/math] 。指数范围 [math]\displaystyle{ e_\min = 1-b=-1022, e_\max=b=1023 }[/math] 。 尾数 52 位,精度 [math]\displaystyle{ p=53 }[/math] ,因此尾数精度为 [math]\displaystyle{ 2^{-52} }[/math] ,尾数取值在 0 ~ [math]\displaystyle{ 1-2^{-52} }[/math] 之间。
其有效数精度为 53 位二进制数(含隐藏位)相当于约 15~16 位十进制数的有效数字([math]\displaystyle{ \lg 2^{53} \approx 15.95 }[/math])。
由于部分语言及软件中,对数值默认用双精度计算来保证数据变化范围,它们会在有效数字超过 15 位或 16 位后出现精度丢失,特别是在原数是 int64
或字符串时。一般也说是数值超过 int53
时发生精度丢失。
如图,对双精度浮点数,除了 0 和无穷、 NaN 外:
- 规格化数 [math]\displaystyle{ (-1)^s 2^{E-1023} (1+M) }[/math] 正数/绝对值范围:[math]\displaystyle{ 2^{-1022} \approx 2.225 \times 10^{-308} }[/math] ~ [math]\displaystyle{ 2^{1023} \times (2 - 2^{-52}) \approx 1.798 \times 10^{308} }[/math]
- 非规格化数 [math]\displaystyle{ (-1)^s 2^{e_\min} M }[/math] 正数/绝对值范围:[math]\displaystyle{ 2^{-1022} \times 2^{-52} \approx 4.941 \times 10^{-324} }[/math] ~ [math]\displaystyle{ 2^{-1022} \times (1 - 2^{-52}) \approx 2.225 \times 10^{-38} }[/math]