Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Apropos / Subsearch:
optional field

IEEE_HANDLER(3M)                                              IEEE_HANDLER(3M)

       ieee_handler - IEEE exception trap handler function

       #include <&lt;floatingpoint.h>&gt;

       int ieee_handler(action,exception,hdl)
       char action[], exception[];
       sigfpe_handler_type hdl;

       This function provides easy exception handling to exploit ANSI/IEEE Std
       754-1985 arithmetic in a C program.  The first two arguments are point-
       ers  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 :
              division       ... division by zero exception
              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.  <&lt;floating-
       point.h>&gt; defines sigfpe_handler_type.

       get will return the location of the current handler routine for  excep-
       tion  cast to an int.  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 == SIGFPE_DEFAULT or SIGFPE_IGNORE; then ieee_handler()
       will disable the trap on exception.  When hdl == SIGFPE_ABORT, any trap
       on  exception  will dump core using abort(3).  clear all disables trap-
       ping on all five exceptions.

       Two steps are required to intercept an IEEE-related  SIGFPE  code  with

       1)     Set up a handler with ieee_handler.

       2)     Perform  a  floating-point operation that generates the intended
              IEEE exception.

       Unlike sigfpe(3), ieee_handler() also adjusts  floating-point  hardware
       mode  bits  affecting IEEE trapping.  For clear, set SIGFPE_DEFAULT, or
       set SIGFPE_IGNORE, the hardware trap is disabled.  For any other set  ,
       the hardware trap is enabled.

       SIGFPE  signals  can be handled using sigvec(2), signal(3V), sigfpe(3),
       or ieee_handler(3M).  In a particular program, to avoid confusion,  use
       only one of these interfaces to handle SIGFPE signals.

       ieee_handler()  normally returns 0 for set .  1 will be returned if the
       action is not available (for instance, not supported in hardware).  For
       get , the address of the current handler is returned, cast to an int.

       A user-specified signal handler might look like this:

              void sample_handler(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 <&lt;signal.h>&gt;.
                     printf("ieee exception code %x occurred at pc %X \n", code, scp->&gt;sc_pc);

       and it might be set up like this:

              extern void sample_handler();
                     sigfpe_handler_type hdl, old_handler1, old_handler2;
                      * save current overflow and invalid handlers
                     old_handler1 = (sigfpe_handler_type) ieee_handler("get", "overflow", old_handler1);
                     old_handler2 = (sigfpe_handler_type) ieee_handler("get", "invalid", old_handler2);
                      * set new overflow handler to sample_handler() and set new
                      * invalid handler to SIGFPE_ABORT (abort on invalid)
                     hdl = (sigfpe_handler_type) sample_handler;
                     if (ieee_handler("set", "overflow", hdl) != 0)
                            printf("ieee_handler can't set overflow \n");
                     if (ieee_handler("set", "invalid", SIGFPE_ABORT) != 0)
                            printf("ieee_handler can't set invalid \n");
                      * restore old overflow and invalid handlers
                     ieee_handler("set", "overflow", old_handler1);
                     ieee_handler("set", "invalid", old_handler2);

       sigvec(2), abort(3), floatingpoint(3), sigfpe(3), signal(3V)

4th Berkeley Distribution         15 May 1989                 IEEE_HANDLER(3M)