sigfpe(3) (BSD Compatibility Package) sigfpe(3)
NAME
sigfpe - signal handling for specific SIGFPE codes
SYNOPSIS
cc [ flag... ] file ... -lucb
#include <signal.h>
#include <floatingpoint.h>
sigfpehandlertype sigfpe(code, hdl)
sigfpecodetype code;
sigfpehandlertype hdl;
DESCRIPTION
This function allows signal handling to be specified for particular
SIGFPE codes. A call to sigfpe defines a new handler hdl for a
particular SIGFPE code and returns the old handler as the value of
the function sigfpe. Normally handlers are specified as pointers to
functions; the special cases SIGFPEIGNORE, SIGFPEABORT, and
SIGFPEDEFAULT allow ignoring, specifying core dump using abort(3),
or default handling respectively.
For these IEEE-related codes:
FPEFLTINEX fp_inexact floating inexact result
FPEFLTDIV fp_division floating division by zero
FPEFLTUND fp_underflow floating underflow
FPEFLTOVF fp_overflow floating overflow
FPEFLTOPERR fp_invalid floating operand error
FPEFLTNAN fp_invalid floating Not-A-Number
default handling is defined to be to call the handler specified to
ieeehandler(3M).
For all other SIGFPE codes, default handling is to core dump using
abort(3).
The compilation option -ffpa causes fpa recomputation to replace the
default abort action for code FPEFPAERROR. Note: SIGFPEDEFAULT
will restore abort rather than FPA recomputation for this code.
Three steps are required to intercept an IEEE-related SIGFPE code
with sigfpe:
1) Set up a handler with sigfpe.
2) Enable the relevant IEEE trapping capability in the
hardware, perhaps by using assembly-language
instructions.
7/91 Page 1
sigfpe(3) (BSD Compatibility Package) sigfpe(3)
3) Perform a floating-point operation that generates the
intended IEEE exception.
Unlike ieeehandler(3M), sigfpe never changes floating-point hardware
mode bits affecting IEEE trapping. No IEEE-related SIGFPE signals
will be generated unless those hardware mode bits are enabled.
SIGFPE signals can be handled using sigvec(2), signal(3), sigfpe(3),
or ieeehandler(3M). In a particular program, to avoid confusion,
use only one of these interfaces to handle SIGFPE signals.
EXAMPLE
A user-specified signal handler might look like this:
void samplehandler( sig, code, scp, addr )
int sig ; /* sig == SIGFPE always */
int code ;
struct sigcontext *scp ;
char *addr ;
{
/*
Sample user-written sigfpe code handler.
Prints a message and continues.
struct sigcontext is defined in <signal.h>.
*/
printf(" ieee exception code %x occurred at pc %X \n",
code,scp->scpc);
}
and it might be set up like this:
extern void samplehandler;
main
{
sigfpehandlertype hdl, oldhandler1, oldhandler2;
/*
* save current overflow and invalid handlers; set the new
* overflow handler to samplehandler and set the new
* invalid handler to SIGFPEABORT (abort on invalid)
*/
hdl = (sigfpehandlertype) samplehandler;
oldhandler1 = sigfpe(FPEFLTOVFTRAP, hdl);
oldhandler2 = sigfpe(FPEFLTOPERRTRAP, SIGFPEABORT);
...
/*
* restore old overflow and invalid handlers
*/
sigfpe(FPEFLTOVFTRAP, oldhandler1);
sigfpe(FPEFLTOPERRTRAP, oldhandler2);
}
Page 2 7/91
sigfpe(3) (BSD Compatibility Package) sigfpe(3)
FILES
/usr/include/floatingpoint.h
/usr/include/signal.h
SEE ALSO
sigvec(2), floatingpoint(3), ieeehand