_matherr -- Process Math Library Errors

Format

#include <math.h>
int _matherr(struct _exception *x);

Language Level: Extension
_matherr processes errors generated by the functions in the math library. The math functions call _matherr whenever they detect an error.

You can provide a different definition of _matherr to carry out special error handling. Be sure to use the /NOE link option, if you are using your own _matherr function. If you do provide your own _matherr, it will get called from the math functions in the event of an error.

When an error occurs in a math routine, _matherr is called with a pointer to the following structure (defined in <math.h>) as an argument:

struct _exception {
   int type;
   char *name;
   double arg1, arg2, retval;
};

The type field specifies the type of math error. It has one of the following values, defined in <math.h>:

Value Meaning
DOMAIN Argument domain error
OVERFLOW Overflow range error
UNDERFLOW Underflow range error
TLOSS Total loss of significance
PLOSS Partial loss of significance
SING Argument singularity.

PLOSS is provided for compatibility with other compilers.

The name is a pointer to a null-ended string containing the name of the function that caused the error. The arg1 and arg2 fields specify the argument values that caused the error. If only one argument is given, it is stored in arg1. The retval is the default return value; you can change it.

Return Value
The return value from _matherr must specify whether or not an error actually occurred. If _matherr returns 0, an error message appears, and errno is set to an appropriate error value. If _matherr returns a nonzero value, no error message appears and errno remains unchanged.

Example



log -- Calculate Natural Logarithm
log10 -- Calculate Base 10 Logarithm
<math.h>
/NOE linker option
/B compiler option