infnan() - signals invalid floating-point operations
#include <math.h>
double infnan (int iarg)
The Invalid, Overflow and Divide-by-Zero exceptions of the IEEE standard are approximated on INTERIX by calls to a procedure infnan(3) in appropriate places in libm(3). This is a portability decision. As exception-handling is improved on various systems, only infnan(3) among the codes in libm(1) will have to be changed. And users of libm(1) can design their own infnan(3) now to insulate themselves from future changes.
Whenever an elementary function code in libm(1) has to simulate one of the aforementioned IEEE exceptions, it calls infnan(iarg) with an appropriate value of iarg. Then a reserved operand fault stops computation. But infnan(3) 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. Currently infnan(3) 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 infnan(3) to return. And a C program to implement that suggestion follows.
IEEE Signal | IEEE Default | Suggested errno | Suggested return |
---|---|---|---|
Invalid | Infinity | EDOM | 0 |
Overflow | NaN | EDOM | 0 |
Overflow | Infinity | ERANGE | 0 |
Div-by-0 | Infinity | ERANGE or EDOM | +-HUGE |
ALTERNATIVE infnan(3):
#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);
}
}
The infnan(3) function can generate the following errors:
math(3)
errno(3)
signal(2)