加算演算が double をアンダーフローするかどうかを判断するコードをデバッグしているときに、少なくとも自分の頭の中で奇妙な動作に遭遇しました。これは、私が見つけたものを示すサンプルプログラムです。
#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 になります。これはバグですか、それとも睡眠不足ですか?