C ++中的long double是否是IEEE的binary128的实现? [英] Is long double in C++ an implementation of IEEE's binary128?
问题描述
来自 https://en.wikipedia.org/wiki/Long_double :
在C ++中,
long double
指的是浮点数据类型,其精度通常比double-精确。但是,与C ++的其他浮点类型一样,它不一定映射到IEEE格式。
In C++,
long double
refers to a floating-point data type that is often more precise than double-precision. However, as with C++'s other floating-point types, it may not necessarily map to an IEEE format.
...
对于GNU C编译器, long double
在x86处理器上具有80位扩展精度,而与该类型所使用的物理存储无关(可以为96位或128位)。在其他一些体系结构上, long double
可以是 double-double
(例如在PowerPC上)或128位四倍精度(例如在SPARC上)。从gcc 4.3开始,x86还支持四倍精度,但作为非标准类型 __ float128
而不是 long double
With the GNU C Compiler, long double
is 80-bit extended precision on x86 processors regardless of the physical storage used for the type (which can be either 96 or 128 bits). On some other architectures, long double
can be double-double
(e.g. on PowerPC) or 128-bit quadruple precision (e.g. on SPARC). As of gcc 4.3, a quadruple precision is also supported on x86, but as the nonstandard type __float128
rather than long double
.
在Linux上使用gcc时,默认为80位扩展精度;在某些BSD操作系统(FreeBSD和OpenBSD)上,默认为双精度模式,长双精度操作有效地减少为双精度。
With gcc on Linux, 80-bit extended precision is the default; on several BSD operating systems (FreeBSD and OpenBSD), double-precision mode is the default, and long double operations are effectively reduced to double precision.
x86上的Intel C ++编译器另一方面,默认情况下启用扩展精度模式。在OS X上,long double是80位扩展精度。
The Intel C++ Compiler for x86, on the other hand, enables extended-precision mode by default. On OS X, long double is 80-bit extended precision.
似乎确实是 long double
可能不是IEEE的binary128的实现,但是为什么不这样做呢?为什么在某些情况下默认使用80位表示形式?
It seems like indeed long double
may not be an implementation of IEEE's binary128, but why not make this the case? Why defaulting to an 80-bit representation on some cases?
推荐答案
为什么默认使用80-位表示形式
Why defaulting to an 80-bit representation on some cases?
因为某些平台可能能够在硬件中提供有效的80位浮点运算,但不能提供128位位的。这与为什么标准未指定 sizeof(int)
的原因相同-在某些平台上32位整数可能无效/不可用。
Because some platforms may be able to provide efficient 80-bit floating point operations in hardware, but not 128-bit ones. This is the same reasoning for why sizeof(int)
is not specified by the standard - on some platforms 32-bit integers might not be efficient/available.
这篇关于C ++中的long double是否是IEEE的binary128的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!