site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com #define DIVIDE(a,b) (assert((b)!=0),(a)/(b)) And use DIVIDE(n,m) instead of n/m. On Mar 17, 2005, at 2:25 PM, Aaron Jackson wrote: On Mar 17, 2005, at 4:55 PM, Matt Watson wrote: fpsetmask(FP_X_INV | FP_X_DZ); signal(SIGFPE, sig_handler); _______________________________________________ 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... If the PPC processor does not throw an exception in this situation, then there's no exception to unmask. Can't do it that way. It is a bug in your code, much like dereferencing a null pointer. All the macros in the header files won't change CPU behavior. For integer division, you may be able to at least break on the attempt to help isolate your problem by doing something like: Once you have found the problem, don't leave it like that if other people are supposed to maintain your code.. This is not a bug. Per the ISO/IEC 9899:1999 C Standard (ยง6.5.5): 5 The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined. Division by zero results in undefined behavior and the compiler is free to do whatever it likes, including crashing the program, or setting the result to zero and continuing. Sorry for jumping to the wrong conclusion. The problem is that I am doing some numerical calculations (solving nonlinear equations with a nonlinear constraint) and the algorithm I am using sometimes wanders off into nowhere (I am still debugging things). I haven't done any c programming in quite a while, and got used to the crashing behavior when I first learned and thought that was how things operated. Since this is undefined, I would like for the program to throw a SIGFPE, as it does on other platforms, for both integer and floating point division by zero. On FreeBSD and OpenBSD, there is a function fpsetmask that I could use to trap invalid operations and division by zero: Unfortunately, the fpsetmask function doesn't seem to exist on my mac, or at least ieeefp.h doesn't. Is there an equivalent function I can use on my mac? Thanks. Aaron This email sent to site_archiver@lists.apple.com
participants (1)
-
Paul Forgey