ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
NAME
ieeehandler - IEEE exception trap handler function
SYNOPSIS
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
Std 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
Note: ``all'' and ``common'' only make sense with ``set'' or
``clear''.
hdl contains the address of a signal-handling routine. <fp.h>
defines sigfpe_handler_type.
``get'' will get 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(3).
``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.
8/91 Page 1
ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
Unlike sigfpe(3), ieeehandler also adjusts floating-point hardware
mode bits affecting IEEE trapping. For ``clear'', ``set''
SIGFPEDEFAULT, or ``set'' SIGFPEIGNORE, the hardware trap is
disabled. For any other ``set'', the hardware trap is enabled.
SIGFPE signals can be handled using sigvec(2), signal(3), signal(3F),
sigfpe(3), or ieeehandler(3M). In a particular program, to avoid
confusion, 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).
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
*/
ieeehandler("get","overflow",oldhandler1);
ieeehandler("get","invalid", oldhandler2);
/*
* set new overflow handler to samplehandler and set new
* invalid handler to SIGFPEABORT (abort on invalid)
*/
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");
...
Page 2 8/91
ieee_handler(3M) (BSD Compatibility Package) ieee_handler(3M)
/*
* 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
floatingpoint(3), ieeehandler(3), sigfpe(3), signal(3) sigvec(3),
signal(2), abort(3C) in the Programmer's Reference Manual.
8/91 Page 3