Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mcnc!uvaarpa!murdoch!astsun.astro.Virginia.EDU!gl8f From: gl8f@astsun.astro.Virginia.EDU (Greg Lindahl) Newsgroups: comp.unix.aix Subject: Help catching floating point exceptions Message-ID: <1991May27.213751.24223@murdoch.acc.Virginia.EDU> Date: 27 May 91 21:37:51 GMT Sender: usenet@murdoch.acc.Virginia.EDU Organization: Department of Astronomy, University of Virginia Lines: 69 After perusing the info reader (man -k fp produces a nice list of man pages which man can't find...), I am attempting to use fp_enable_all to generate floating point traps. It isn't clear from the manual what an FP trap is on an RS/6000. Nevertheless, I'm still praying that there's a way to get my programs to die gracelessly when they hit a problem. The program below calls fp_enable_all() and then divides by zero. No signal is generated, but an explicit test for divide by zero produces a positive result. a is 1.000000 b is 0.000000 floating point traps ARE enabled. divide by zero trap IS enabled. a/b is 1.000000 divide by zero error. How do I get AIX to generate a signal? And why isn't this discussed in the Fortran manual? Advance thanks. Program below. -- greg ------------------------------ cut here ------------------------------ #include #include #include double foo( double b ); void myfunc( int i ) { printf( "myfunc hit with argument %d\n", i ); } main() { int i; fp_enable_all(); fp_enable( TRP_DIV_BY_ZERO ); for( i = 1 ; i < 64 ; i++ ) /* catch all signals */ (void) signal( i, myfunc ); (void)foo( (double) 0.); } double foo( double b ) { double a = 1.; /* raise( SIGFPE );*/ /* works as expected if you uncomment */ printf( "a is %f\n", a ); printf( "b is %f\n", b ); if( fp_any_enable() ) printf( "floating point traps ARE enabled.\n" ); if( fp_is_enabled( TRP_DIV_BY_ZERO ) ) printf( "divide by zero trap IS enabled.\n" ); printf( "a/b is %f\n", a/b ); /* should generate exception */ if( fp_divbyzero() ) printf( "divide by zero error.\n" ); /* this sees the flag set */ return( a/b ); /* should generate another exception */ }