I'm trying to understand the strange behavior of the following program. Obviously, an overflow occurs during the definition of the global variable "bug", but the program throws a floating point exception during the innocent calculation 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;
}
I tried compiling it with both g++ and clang++, but got the same output in both
before
Floating point exception