site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 On 9/05/07 1:29, Kristoffer Eriksen wrote: Hi- [...] [...]
From the Mac_OSX_Numerics.pdf (which still seems to apply): Floating-point exceptions are signaled with exception flags. When an application begins, all floating-point exception flags are cleared and the default rounding direction (round to nearest) is in effect. This is the default environment. When an exception occurs, the appropriate exception flag is set, but the application continues normal operation. Floating-point exception flags merely indicate that a particular event has occurred; they do not change the flow of control for the application. An application can examine or set individual exception flags and can save and retrieve the entire environment (rounding direction and exception flags). #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; pid = getpid(); /* Just to be sure ;-) */ feclearexcept(FE_ALL_EXCEPT); /* This will set the FE_INEXACT flag */ x = 1.0/(double)pid; retval = fetestexcept(FE_ALL_EXCEPT); feclearexcept(FE_ALL_EXCEPT); /* This will set the FE_INVALID flag */ x = sqrt(-x); retval = fetestexcept(FE_ALL_EXCEPT); if (retval != 0) raise(SIGFPE); printf("%d %d %f\n",retval,pid,x); exit(0); }
HTH, Axel _______________________________________________ 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. 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'm a scientist, not a systems programmer, so I may just be doing something stupid here. Any ideas? Function feraiseexcept() doesn't raise an exception, it only raises one or more exception flags. So, taking your example, but made somewhat more verbose for seeing what's happening: This email sent to site_archiver@lists.apple.com