I can't get even a simple C++ code to trap fpu errors, no matter what combination of compile options or signal handling I attempt. Can anyone point me to some definitive documation on this? Thanks.
#include <iostream>
#include <cmath>
#include <signal.h>
int main()
{
signal(SIGFPE, exit);
for (int i=0; i<10; i++) {
double arg = -5 + i;
double recip = 1. / arg;
std::cerr << arg << " " << recip << std::endl;
}
}
And here is the compile command with every possible non-optimization and fpu-related option that I could find, set to its pickiest setting:
% cc junk.C -g -O0 -lc -lstdc++ -Wl,-m -Wl,-w -lm -fsignaling-nans -ftrapping-math -fno-unsafe-math-optimizations
% ./a.out
-5 -0.2
-4 -0.25
-3 -0.333333
-2 -0.5
-1 -1
0 inf
1 1
2 0.5
3 0.333333
4 0.25
The code should exit/crash prior to outputting the 6th line.
Thanks.
#include <iostream>
#include <cmath>
#include <signal.h>
int main()
{
signal(SIGFPE, exit);
for (int i=0; i<10; i++) {
double arg = -5 + i;
double recip = 1. / arg;
std::cerr << arg << " " << recip << std::endl;
}
}
And here is the compile command with every possible non-optimization and fpu-related option that I could find, set to its pickiest setting:
% cc junk.C -g -O0 -lc -lstdc++ -Wl,-m -Wl,-w -lm -fsignaling-nans -ftrapping-math -fno-unsafe-math-optimizations
% ./a.out
-5 -0.2
-4 -0.25
-3 -0.333333
-2 -0.5
-1 -1
0 inf
1 1
2 0.5
3 0.333333
4 0.25
The code should exit/crash prior to outputting the 6th line.
Thanks.