MATHERR(3M) SysV MATHERR(3M)
NAME
matherr - error-handling function
SYNOPSIS
#include <math.h>
int matherr (x)
struct exception *x;
DESCRIPTION
matherr is invoked by functions in the Math Library when errors are
detected. Which matherr function your program invokes depends upon the
startup routine to which you link it.
You may define your own procedure for handling errors by including a
function named matherr in your program and linking it to /usr/lib/crt0.o
or to /usr/apollo/lib/svid/crt0.o. You must either compile your program
with the -A nansi option to cc(1), or make sure it contains one of the
following directives (listed in order of increasing restrictiveness)
before any #include directive:
#define _APOLLO_SOURCE
#define _SYS5_SOURCE
matherr must be of the form described above. When an error occurs, a
pointer to the exception structure x will be passed to the user-supplied
matherr function. This structure, which is defined in the <math.h>
header file, is as follows:
struct exception {
int type;
char *name;
double arg1;
double arg2;
double retval;
};
The element type is an integer describing the type of error that has
occurred. It is taken from following list of constants (defined in the
header file):
DOMAIN argument domain error
SING argument singularity
OVERFLOW overflow range error
UNDERFLOW underflow range error
TLOSS total loss of significance
PLOSS partial loss of significance
The element name points to a string containing the name of the function
that incurred the error. The variables arg1 and arg2 are the arguments
with which the function was invoked. retval is set to the default value
that will be returned by the function unless your matherr sets it to a
different value.
Linking your program to /usr/lib/crt0.o causes the math functions to
behave according to the common C semantics documented in their respective
manual pages. In this case, if your matherr function returns zero, an
error message will be printed, and errno will be set.
If you link your program to /usr/apollo/lib/crt0.o (the default),
Domain/OS calls its own matherr function and ignores any your program may
contain. In this case, and in the case where you link your program to
/usr/apollo/lib/svid/crt0.o without defining your own matherr function,
the math functions invoke the default error-handling procedures,
described in their respective manual pages. These procedures are also
summarized in the table below. In every case, errno is set to EDOM or
ERANGE and the program continues.
EXAMPLE
#include <math.h>
int
matherr(x)
register struct exception *x;
{
switch (x->type) {
case DOMAIN:
/* change sqrt to return sqrt(-arg1), not 0 */
if (!strcmp(x->name, "sqrt")) {
x->retval = sqrt(-x->arg1);
return (0); /* print message and set errno */
}
case SING:
/* all other domain or sing errors, print message and abort */
fprintf(stderr, "domain error in %s\n", x->name);
abort( );
case PLOSS:
/* print detailed error message */
fprintf(stderr, "loss of significance in %s(%g) = %g\n",
x->name, x->arg1, x->retval);
return (1); /* take no other action */
}
return (0); /* all other errors, execute default procedure */
}
______________________________________________________________________________
______________________DEFAULT_ERROR_HANDLING_PROCEDURES_______________________|
______________________________________________________________________________|
__________________________________________Types_of_Errors_____________________|
______________________________________________________________________________|
_________type__________DOMAIN___SING__OVERFLOW____UNDERFLOW___TLOSS____PLOSS__|
______________________________________________________________________________|
________errno___________EDOM____EDOM___ERANGE_______ERANGE____ERANGE___ERANGE_|
______________________________________________________________________________|
_BESSEL:_________________-_______-________-___________-_________0________*____|
|y0, y1, yn (arg < 0) | -H | - | - | - | - | - |
______________________________________________________________________________|
|EXP: | - | - | H | 0 | - | - |
______________________________________________________________________________|
|LOG, LOG10: | | | | | | |
______________________________________________________________________________|
__(arg_<_0)______________-H______-________-___________-_________-________-____|
| (arg = 0) | - |-H | - | - | - | - |
______________________________________________________________________________|
|POW: | - | - | +H | 0 | - | - |
______________________________________________________________________________|
_neg_**_non-int__________0_______-________-___________-_________-________-____|
| 0 ** non-pos | | | | | | |
______________________________________________________________________________|
|SQRT: | 0 | - | - | - | - | - |
______________________________________________________________________________|
|GAMMA: | - | H | H | - | - | - |
______________________________________________________________________________|
|HYPOT: | - | - | H | - | - | - |
______________________________________________________________________________|
|SINH: | - | - | +H | - | - | - |
______________________________________________________________________________|
|COSH: | - | - | H | - | - | - |
______________________________________________________________________________|
|SIN, COS, TAN: | - | - | - | - | 0 | * |
______________________________________________________________________________|
|ASIN, ACOS, ATAN2: | 0 | - | - | - | - | - |
______________________________________________________________________________|
_____________________________________________________
| ABBREVIATIONS |
| * As much as possible of the value is returned. |
| H HUGE_VAL is returned. |
| -H -HUGE_VAL is returned. |
| +H HUGE_VAL or -HUGE_VAL is returned. |
| 0 0 is returned. |
_____________________________________________________|
SEE ALSO
cc(1), exp(3M), floor(3M), frexp(3C), logname(3X), sinh(3M), trig(3M)
NOTES
If you require the HUGE macro to be a compile-time constant, add the
directive
#define _CLASSIC_HUGE
before any #include directives. Programs compiled with _CLASSIC_HUGE are
forward-compatible only if linked with /usr/lib/crt0.o.