四精度浮点数

来自GSXAB的知识库
四精度浮点数
术语名称 四精度浮点数
英语名称 quadruple-precision floating-point type
别名 quad-precision floating-point tyoe, quadruple-precision floating-point format, quad-precision floating-point format, 四精度浮点型, float128, binary128, 128位浮点数, 128-bit floating-point format

四精度浮点数/四精度浮点型(quadruple-/quad-precision floating-point number)是浮点型中长 128 二进制位数据类型,符合 IEEE 754 中 binary128 类型的格式。根据长度,称为 float128 或 binary128 。

四精度浮点数并没有得到大部分硬件直接支持,一般编译器在编译到四精度时,会提供单独的库用于链接,并在其中提供软件实现相关运算操作。由于使用软件实现,速度比双精度还要慢很多。在实践中,四精度基本只用在精密数值算法、气候及天文等长期大量数据分析等需要高精度、大范围、低舍入误差的场景下。

定义

四精度浮点数(quadruple-precision floating-point type)或 float128FP128binary128 ,指长度为 128 位、符合 IEEE 754 中 binary128 类型浮点格式的浮点类型。

其中浮点数的 128 位包括符号位 1 位、阶码 15 位、尾数 112 位。

floating_point_binary128.svg

范围

阶码 15 位,因此阶码偏移量为 [math]\displaystyle{ b=2^{15-1}-1=16383 }[/math] 。指数范围 [math]\displaystyle{ e_\min = 1-b=-16382, e_\max=b=16383 }[/math] 。 尾数 112 位,精度 [math]\displaystyle{ p=113 }[/math] ,因此尾数精度为 [math]\displaystyle{ 2^{-112} }[/math] ,尾数取值在 0 ~ [math]\displaystyle{ 1-2^{-112} }[/math] 之间。

其有效数精度为 113 位二进制数(含隐藏位)相当于约 34~35 位十进制数的有效数字([math]\displaystyle{ \lg 2^{113} \approx 34.02 }[/math])。

对四精度浮点数,除了 0 和无穷、 NaN 外:

  • 规格化数 [math]\displaystyle{ (-1)^s 2^{E-16383} (1+M) }[/math] 正数/绝对值范围:[math]\displaystyle{ 2^{-16382} \approx 3.362 \times 10^{-4932} }[/math][math]\displaystyle{ 2^{16383} \times (2 - 2^{-112}) \approx 1.190 \times 10^{4932} }[/math]
  • 非规格化数 [math]\displaystyle{ (-1)^s 2^{e_\min} M }[/math] 正数/绝对值范围:[math]\displaystyle{ 2^{-16382} \times 2^{-112} \approx 6.475 \times 10^{-4966} }[/math][math]\displaystyle{ 2^{-16382} \times (1 - 2^{-112}) \approx 3.362 \times 10^{-4932} }[/math]