实际的长双精度与std :: numeric

编程入门 行业动态 更新时间:2024-10-22 14:36:00
实际的长双精度与std :: numeric_limits不一致(Actual long double precision does not agree with std::numeric_limits)

在Mac OS X 10.6.2,Intel,使用i686-apple-darwin10-g ++ - 4.2.1,并使用-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

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

最满意答案

这是因为1e309是一个双倍的文字。 你需要使用long-double literal 1e309L 。

It's because 1e309 is a literal that gives a double. You need to use a long-double literal 1e309L.

更多推荐

本文发布于:2023-08-06 23:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精度   std   numeric

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!