5
至少在我自己的想法中,我遇到了一些奇怪的行为,同时调试一些涉及确定添加操作是否会使双精度下溢的代码。这是一个演示我发现的示例程序。在numeric_limits中有一个错误,或者我只是困惑?
#include <iostream>
#include <limits>
using std::cout;
using std::endl;
using std::numeric_limits;
int main()
{
double lowest = numeric_limits<double>::lowest();
bool truth = (lowest + 10000) == lowest;
cout << truth << endl;
}
当我执行此代码时,我得到true作为结果。这是一个错误还是我只是睡觉剥夺?
OP(例如Matthew)绝对应该阅读http://floating-point-gui.de/ – 2014-09-11 05:25:29
@MatthewPapageorge也看看:[双精度浮点格式](http://en.wikipedia.org/ wiki/Double-precision_floating-point_format) – Rimas 2014-09-11 05:29:37
感谢您的迅速和明确的回应,约翰。对此,我真的非常感激。感谢Basile和Rimas阅读材料。 – 2014-09-11 05:34:42