matherr(3) CLIX matherr(3)
NAME
matherr - Error-handling function
LIBRARY
Standard Math Library (libm.a)
Intergraph Math Library (libmath.a)
SYNOPSIS
#include <math.h>
int matherr(
struct exception *x );
PARAMETERS
x An exception structure.
DESCRIPTION
The matherr() function is invoked by functions in the math libraries when
errors are detected. Users may define their own procedures for handling
errors, by including a function named matherr() in their programs. The
matherr() function must be of the form described above. When an error
occurs, a pointer to the exception structure x is 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, arg2, retval;
};
The element type is an integer describing the type of error, from the
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.
2/94 - Intergraph Corporation 1
matherr(3) CLIX matherr(3)
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. The retval is set to the default
value that is returned by the function unless the user's matherr() sets it
to a different value.
If the user's matherr() function returns nonzero, no error message is
displayed, and errno is not set.
If matherr() is not supplied by the user, the default error-handling
procedures, described with the math functions involved, is invoked upon
error. These procedures are also summarized in the table below. In every
case, errno() is set to EDOM or ERANGE and the program continues.
___________________________________________________________________________
| | Types of Errors |
|_____________________|______|_______|__________|___________|_______|______|
| Type |DOMAIN| SING | OVERFLOW | UNDERFLOW | TLOSS | PLOSS|
|_____________________|______|_______|__________|___________|_______|______|
| errno | EDOM | EDOM | ERANGE | ERANGE | ERANGE| ERANGE
|
|_____________________|______|_______|__________|___________|_______|______|
| BESSEL: | - | - | - | - | M, 0 | * |
| y0, y1, yn (arg < 0)|M, -H | - | - | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| EXP: | - | - | H | 0 | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| LOG, LOG10: | | | | | | |
| (arg < 0) |M, -H | - | - | - | - | - |
| (arg = 0) | - | M, -H | - | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| POW: | - | - | +H | 0 | - | - |
| neg ** nonint |M, 0 | - | - | - | - | - |
| 0 ** nonpos | | | | | | |
|_____________________|______|_______|__________|___________|_______|______|
| SQRT: | M, 0 | - | - | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| GAMMA: | - | M, H | H | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| HYPOT: | - | - | H | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| SINH: | - | - | +H | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| COSH: | - | - | H | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
| SIN, COS, TAN: | - | - | - | - | M, 0 | * |
|_____________________|______|_______|__________|___________|_______|______|
| ASIN, ACOS, ATAN2: | M, 0 | - | - | - | - | - |
|_____________________|______|_______|__________|___________|_______|______|
2 Intergraph Corporation - 2/94
matherr(3) CLIX matherr(3)
_____________________________________________________
| ABBREVIATIONS |
|____________________________________________________|
| * As much as possible of the value is returned.|
| M Message is displayed (EDOM error). |
| H HUGE is returned. |
| -H -HUGE is returned. |
| +H HUGE or -HUGE is returned. |
| 0 0 is returned. |
|____________________________________________________|
EXAMPLES
The following uses matherr():
#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 */
}
/* all other errors, execute default procedure */
return (0);
}
2/94 - Intergraph Corporation 3