site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Hi- #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); } If I compile with: gcc feexcept.c -lm -Wall --std=c99 damocles:~/Research/feexcept[134] a.out 0 7065 nan Thanks, Kris Eriksen _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 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: To summarize, I'm using the feraiseexcept() function from fenv.h, which I had hoped would enable floating point exceptions for the requested flags. I get no compile errors or warnings. Unfortunately, the code runs to the end: 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? This email sent to site_archiver@lists.apple.com