0

次のプログラムの奇妙な動作を理解しようとしています。明らかに、グローバル変数「bug」の定義中にオーバーフローが発生しますが、プログラムは無害な計算 1.0+2.0 中に浮動小数点例外をスローします。

#include <iostream>
#include <cmath>
#include <fenv.h>

using namespace std;

const double bug = pow(10.0,pow(10.0,10.0));

int main(void)
{
  feenableexcept(-1);

  cout << "before" << endl;
  cout << 1.0 + 2.0 << endl;
  cout << "after" << endl;

  return 0;
}

g ++とclang ++の両方でコンパイルしようとしましたが、両方で同じ出力が得られました

before
Floating point exception
4

2 に答える 2