catching floating point exception on OS X Intel
catching floating point exception on OS X Intel
- Subject: catching floating point exception on OS X Intel
- From: Kristoffer Eriksen <email@hidden>
- Date: Tue, 8 May 2007 16:29:26 -0700
Hi-
I tried this question on darwin-x86 to no avail, so I thought I
would try here.
I am writing a large numerical code as part of my PhD dissertation.
After coding for Linux for quite a while, I recently bought a quad-
core 3.0 GHz Xeon MacPro, and am having a horrible time getting my
code to trap floating point exceptions. I'm compiling with a standard
Unix Makefile rather than Xcode, and an experimental GCC 4.3 release,
which I need for its OpenMP support, though I get the same behavior
with the standard /usr/bin/gcc (4.0.1). I am using OS X 10.4.8.
For example, I would like this code to crash on an invalid floating
point operation:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fenv.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[]){
double x;
int retval;
pid_t pid;
retval = -1;
retval = feraiseexcept( FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW );
pid = getpid();
x = sqrt(-1.0/(double)pid);
printf("%d %d %f\n",retval,pid,x);
//raise(SIGFPE);
exit(0);
}
To summarize, I'm using the feraiseexcept() function from fenv.h,
which I had hoped would enable floating point exceptions for the
requested flags.
If I compile with:
gcc feexcept.c -lm -Wall --std=c99
I get no compile errors or warnings. Unfortunately, the code runs to
the end:
damocles:~/Research/feexcept[134] a.out
0 7065 nan
It correctly generates the nan, but doesn't crash. For kicks, if I
raise a SIGFPE manually, it crashes like it's supposed to, meaning
that the default behavior for a SIGFPE is correct.
I've found some examples about getting this to work on older Macs,
but they all involve PPC assembly, which isn't an option here.
I'm a scientist, not a systems programmer, so I may just be doing
something stupid here. Any ideas?
Thanks,
Kris Eriksen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden