Whenever an elementary function code in libm has to simulate one of the aforementioned IEEE exceptions, it calls Fn infnan iarg with an appropriate value of Fa iarg . Then a reserved operand fault stops computation. But Fn infnan could be replaced by a function with the same name that returns some plausible value, assigns an apt value to the global variable errno and allows computation to resume. Alternatively, the Reserved Operand Fault Handler could be changed to respond by returning that plausible value, etc. instead of aborting.
In the table below, the first two columns show various exceptions signaled by the IEEE standard, and the default result it prescribes. The third column shows what value is given to Fa iarg by functions in libm when they invoke Fn infnan iarg under analogous circumstances on a VAX . Currently Fn infnan stops computation under all those circumstances. The last two columns offer an alternative; they suggest a setting for errno and a value for a revised Fn infnan to return. And a C program to implement that suggestion follows.
- IEEE Signal IEEE Default Ta Fa iarg Ta errno Ta Fn infnan
- Invalid Ta EDOM EDOM 0
- Overflow± Ta ERANGEERANGEHUGE
- Div-by-0±Infinity Ta ±ERANGEERANGE or EDOM±HUGE
- ( HUGE = 1.7e38 ... nearly 2.0**127)
ALTERNATIVE
Fn infnan :
#include <math.h> #include <errno.h> extern int errno ; double infnan(iarg) int iarg ; { switch(iarg) { case ERANGE: errno = ERANGE; return(HUGE); case -ERANGE: errno = EDOM; return(-HUGE); default: errno = EDOM; return(0); } }
ERANGE and EDOM are defined in Aq Pa errno.h . (See intro(2) for explanation of EDOM and ERANGE .