Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!think!ames!sgi!deb@kea.wpd.sgi.com From: deb@kea.wpd.sgi.com (Deb Ryan) Newsgroups: comp.sys.sgi Subject: Re: SIGFPE Summary: trap handler info Message-ID: <46227@sgi.sgi.com> Date: 13 Dec 89 01:05:06 GMT References: <8912111534.AA25453@prism.gatech.edu> <624@chem.ucsd.EDU> Sender: deb@kea.wpd.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 72 In article <624@chem.ucsd.EDU>, tps@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@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 #include #include /* 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@sgi.com Deborah Ryan Caruso @ Silicon Graphics