Substitutes a custom routine for matherr.
#include <math.h>
int matherr_handler (
int (*newFunc)(_FP_EXCEPTION *err_info));
(IN) Points to the function to be used as the matherr function.
If successful, returns 0. If a nonzero value is returned, an error occurred and no error handler was registered.
If a routine has already been registered, matherr_handler returns a nonzero value.
The following unregisters a previously registered matherr handler:
matherr_handler(NULL);
The routine that is registered must meet the requirements of matherr.
For more information on developing a matherr handler, see Section 17.1, Writing a Math Error Handler.
The following code is more or less what LibC does when no matherr handler is registered.
#include <math.h>
int mymatherr
(
__FP_EXCEPTION *exc
)
{
char *msg;
/*
** Protect against a bad calling parameter which could cause
** us to index beyond the valid messages or foul up a user
** error handler. We don’t permit any localization of these
** strings because they are fixed though in English.
*/
if (exc->type < DOMAIN || exc->type > PLOSS)
exc->type = DOMAIN;
switch (exc->type)
{
default :
break;
case DOMAIN :
msg = "Domain error";
break;
case SING :
msg = "Argument singularity";
break;
case OVERFLOW :
msg = "Overflow range error";
break;
case UNDERFLOW :
msg = "Underflow range error";
break;
case TLOSS :
msg = "Total loss of significance";
break;
case PLOSS :
msg = "Partial loss of significance";
break;
}
#define ERR_PROMPT "MyNLM-1.0-100: %s in %s\n"
fprintf(stderr, ERR_PROMPT, msg, exc->name);
return exc->retval;
}