I'm repeating the same calculation twice, but in one I get a floating point exception while in the other I don't.
#include <iostream>
#include <cmath>
#include <fenv.h>
using namespace std;
int main(void)
{
feenableexcept(-1);
double x,y,z;
x = 1.0;
y = (1.0/(24.3*24.0*3600.0))*x;
cout << "y = " << y << endl;
z = x/(24.3*24.0*3600.0);
cout << "z = " << z << endl;
return 0;
}
I tested it on both g++ and clang++ and got the following output in both
y = 4.76299e-07
Floating point exception
What's going on?