ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
NAME
ieeehandler - IEEE exception trap handler function
SYNOPSIS
/usr/ucb/cc [flag ...] file ... -lucb
#include <fp.h>
int ieeehandler(action, exception, hdl)
char action[], exception[];
sigfpehandlertype hdl;
DESCRIPTION
This function provides easy exception handling to exploit ANSI/IEEE
Standard 754-1985 arithmetic in a C program. All arguments are
pointers to strings. Results arising from invalid arguments and
invalid combinations are undefined for efficiency.
There are three types of action: "get", "set", and "clear". There are
five types of exception:
"inexact"
"division" ... division by zero exception
"underflow"
"overflow"
"invalid"
"all" ... all five exceptions above
"common" ... invalid, overflow, and division exceptions
The exceptions "all" and "common" only make sense with "set" or
"clear".
hdl contains the address of a signal-handling routine. <fp.h> defines
sigfpehandlertype.
"get will find the location of the current handler routine for
exception in hdl. "set" will set the routine pointed at by hdl to be
the handler routine and at the same time enable the trap on exception,
except when hdl == SIGFPEDEFAULT or SIGFPEIGNORE; then ieeehandler
will disable the trap on exception. When hdl == SIGFPEABORT, any trap
on exception will dump core using abort(3C). "clear" "all" disables
trapping on all five exceptions.
Two steps are required to intercept an IEEE-related SIGFPE code with
ieeehandler:
1) Set up a handler with ieeehandler.
2) Perform a floating-point operation that generates the intended
IEEE exception.
Page 1 Reliant UNIX 5.44 Printed 11/98
ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
Unlike sigfpe, ieeehandler also adjusts floating-point hardware mode
bits affecting IEEE trapping. The hardware trap is disabled when these
actions are performed: "clear", "set" SIGFPEDEFAULT or "set"
SIGFPEIGNORE.
The hardware trap is enabled when any other "set" is used.
SIGFPE signals can be handled using sigvec(3), signal(2), signal(3-ucb),
sigfpe(3), or ieeehandler(3M). In a particular program, to avoid confu-
sion, use only one of these interfaces to handle SIGFPE signals.
RETURN VALUE
ieeehandler normally returns 0. In the case of set, 1 will be
returned if the action is not available (for instance, not supported
in hardware).
EXAMPLES
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
*/
ieeehandler("get","overflow",oldhandler1);
ieeehandler("get","invalid", oldhandler2);
/*
* set new overflow handler to samplehandler and set new
* invalid handler to SIGFPEABORT (abort on invalid)
*/
Page 2 Reliant UNIX 5.44 Printed 11/98
ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
hdl = (sigfpehandlertype) samplehandler;
if(ieeehandler("set","overflow",hdl) != 0)
printf("ieeehandler can't set overflow \n");
if(ieeehandler("set","invalid",SIGFPEABORT) != 0)
printf("ieeehandler can't set invalid \n");
...
/*
* restore old overflow and invalid handlers
*/
ieeehandler("set","overflow", oldhandler1);
ieeehandler("set","invalid", oldhandler2);
}
FILES
/usr/include/fp.h
/usr/include/signal.h
SEE ALSO
signal(2), sigfpe(3), sigvec(3), signal(3-ucb), abort(3C),
floatingpoint(3M).
Page 3 Reliant UNIX 5.44 Printed 11/98