SIGFPE
    Deb Ryan 
    deb at kea.wpd.sgi.com
       
    Wed Dec 13 12:05:06 AEST 1989
    
    
  
In article <624 at chem.ucsd.EDU>, tps at chem.ucsd.edu (Tom Stockfisch) writes:
> With 3.2 floating point exceptions are ignored, with NaN's and Infinity's
> propagated through floating point exceptions, presumably according to
> IEEE rules.  I happen to prefer that all exceptions result in SIGFPE
> being raised, so that a process stops right away and either aborts
> or calls a signal()-specified error handler.
> 
> How can I achieve this?
> -- 
> 
> || Tom Stockfisch, UCSD Chemistry	tps at chem.ucsd.edu
You two choices:
1. Wait for the trap handler, comming out in the aspen release.
   This will make it easy to core dump, or do anything your heart can code
   in a subroutine .
2. If all you really want to do is coredump, this  Fortran
   callable C routine will show you what to do.  signal (2) will also
   allow you to specify your own handler, but you will be pretty limited
   without information about the exception.
----------------------------------cut here -------------------------------------
#include <stdio.h>
#include <signal.h>
#include <sys/fpu.h>
/* this code uses information from the manpages fpc(3c) and signal(2)
   set_traps is a fortran callable subroutine which will enable
   foating point exceptions, and coredump upon recieving one
 */
set_traps_() {
union fpc_csr fpstat;
/* enable the floating point traps
 */
 fpstat.fc_word = get_fpc_csr();
 fpstat.fc_word |= (FPCSR_ENABLES | FPCSR_EXCEPTIONS);
 set_fpc_csr (fpstat.fc_word);
/* abort upon recieving floating point trap 
 */
signal (SIGFPE, SIG_DFL);
}
/* test routine for set_traps
 */
main() {
float zero=0.0;
float one=1.0;
float result;
	set_traps_();
	/* divide by zero */
	printf( "\n\ndividing by zero:\n");
	result = one/zero;
	printf("one/zero yields %e\n",result);
}
--
					-Deb
					 deb at sgi.com
 					 Deborah Ryan Caruso @ Silicon Graphics
    
    
More information about the Comp.sys.sgi
mailing list