1

使用 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 个字节,它们应该是。

最后, using<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

4

1 回答 1

5

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

于 2010-04-02T07:27:03.237 回答