HP C/iX Library Reference Manual (30026-90004)

248 Chapter5
HP C/iX Library Function Descriptions
matherr
it to a different value.
Consult the function descriptions in this chapter to determine if a specific function calls
matherr.
If your matherr function returns nonzero, no error message is printed, and errno is not
set.
If matherr is not supplied, the default error-handling procedures, described with the math
functions involved, are invoked upon error. In every case, errno is set to EDOM or ERANGE,
and the program continues.
Example
#include <math.h>
int matherr(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 */
(void) fprintf(stderr, "domain error in %s\n", x->name);
abort( );
case PLOSS:
/* print detailed error message */
(void) 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 */
}