How to trap fpu exceptions on macbook pro?

Joined
Aug 3, 2004
Messages
39
Reaction score
0
Points
6
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.
 
OP
M
Joined
Aug 3, 2004
Messages
39
Reaction score
0
Points
6
Furthermore, I can't get this to work on PowerPC macs either. So any help even getting this to go for non-intel mac would be much appreciated. Thanks.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top