FPSIGSET(3C) — Silicon Graphics
NAME
fpsigset − C floating point exception handling system
SYNOPSIS (C)
#include <fperr.h>
fpsigset (handler,flag)
int (∗handler ( ));
int flag;
DESCRIPTION
fpsigset is used to control reporting and handling of floating point exceptions from C. Unless the appropriate routine of fpsigset is called at program initiation, floating point exceptions will not be detected, and may produce indeterminate results. A call to fpsigset initiates floating-point error detection and determines which types of errors are to be raised as exceptions and the actions to occur.
Once a floating-point exception is raised, the default action is to print a message and abort with a core dump. The call to fpsigset allows the user to specify which combination of the message, the core dump, and the program abort should occur. The call to fpsigset also allows specification of a user handler function which is called when floating-point exception processing is initiated. If floating-point is being emulated by software, the result of the operation raising the exception may be altered by this handler function.
User-control is provided by the second parameter flag. This parameter is a combination (logical or) of any of the following values (defined in fpsignal.h):
NOFPE_ABORTContinue after the exception.
NOFPE_DUMPSuppress the core dump when aborting.
NOFPE_MSGSuppress the printing of an error message.
IGN_DIVZEROIgnore divide-by-zero errors.
IGN_OVERFLOWIgnore overflow errors.
IGN_ZEROVALSIgnore underflow and denormalized operand errors.
IGN_NANOPIgnore not-a-number operand errors.
IGN_ILLEGALOPIgnore illegal operation errors.
Any errors which are not ignored will cause the initiation of exception processing.
If the second argument to fpsigset is not NULL, it will be used as the address of a handler function to be called when exception processing is begun. Information about the exception is communicated to the handler function through a global data structure _fperror. This structure always contains one of the exception codes listed in fperr.h (field code). If floating-point operations are being performed in software, this data structure also contains a floating-point value (field union val), the precision of the operation (field precision), and a code indicating the operation in progress (field operation). The precision field must be used to select the proper value from the union val field. This value will be used as the result of the operation if the NOFPE_ABORT option has been selected. (In the case of floating-point compare, the value found in _fperror replaces the erroneous operand and the comparison is re-tried.) The result of an operation which has been performed in hardware is indeterminate, and cannot be altered by the handler function.
If no user handler function is being used, the smaller include file fpsignal.h may be used in place of fperr.h. It contains only the definitions for the bits in the flag parameter to fpsigset.
EXAMPLES
If it is desired to simply print a message concerning the floating-point error and continue, the call
fpsigset(0,NOFPE_ABORT);
would suffice. The example
fpsigset(fpe_handle,(IGN_ZEROVALS|NOFPE_MSG));
will not flag denormalized operands or underflows as exceptions, and will call the function fpe_handle at the beginning of exception processing. When fpe_handle finishes, the program will be aborted with a core dump without printing a message.
The error types and conditions are more completely discussed in the paper “IRIS Floating Point” in the UNIX Programmer’s Manual, Volume IIB.
SEE ALSO
setfpe(3X)
“IRIS Floating Point”, UNIX Programmer’s Manual, Volume IIB.
Version 2.4 — May 08, 1986