实际的长双精度与std :: numeric_limits不一致 [英] Actual long double precision does not agree with std::numeric_limits
问题描述
使用i686-apple-darwin10-g ++-4.2.1在Mac OS X 10.6.2,Intel上编译并使用-arch x86_64标记进行编译,但我注意到,尽管...
std :: numeric_limits< long double> :: max_exponent10 = 4932
...正如预期的那样,当一个long double被实际设置为一个指数大于308的值时,它就变成了inf - 即实际上它只有64位精度而不是80位。
此外, sizeof()
显示长双打为16个字节,它们应该是。
最后,使用< limits.h>
给出与< limits>
。
有人知道这个差异可能在哪里吗?
long double x = 1e308,y = 1e309;
cout<< std :: numeric_limits< long double> :: max_exponent10<< ENDL;
cout<< x<< '\t'<< y<< ENDL;
cout<< sizeof(x)<< ENDL;
给出
4932
1e + 308 inf
16
1e309
是一个给出double的文字。你需要使用一个long-double文字 1e309L
。 Working on Mac OS X 10.6.2, Intel, with i686-apple-darwin10-g++-4.2.1, and compiling with the -arch x86_64 flag, I just noticed that while...
std::numeric_limits<long double>::max_exponent10 = 4932
...as is expected, when a long double is actually set to a value with exponent greater than 308, it becomes inf--ie in reality it only has 64bit precision instead of 80bit.
Also, sizeof()
is showing long doubles to be 16 bytes, which they should be.
Finally, using <limits.h>
gives the same results as <limits>
.
Does anyone know where the discrepancy might be?
long double x = 1e308, y = 1e309;
cout << std::numeric_limits<long double>::max_exponent10 << endl;
cout << x << '\t' << y << endl;
cout << sizeof(x) << endl;
gives
4932
1e+308 inf
16
It's because 1e309
is a literal that gives a double. You need to use a long-double literal 1e309L
.
这篇关于实际的长双精度与std :: numeric_limits不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!