Article ID: 167750
Article Last Modified on 9/23/2003
#include <stdio.h>
#include <math.h>
#include <ERRNO.H>
#include <string.h>
extern int errno;
/* The _matherr routine can be customized to handle the specific
underflow problem that is encountered. See online help for
more information on _matherr().
*/
int _matherr( struct _exception *except )
{
/* Handle errors caused by pow() function.*/
if(strcmp(except->name,"pow")==0)
{
switch(except->type)
{
case _DOMAIN:
{
printf("Domain Error: Argument not in domain.\n");
return 1;
break;
}
case _SING:
{
printf("Singularity Error: Argument singularity "
"error.\n");
return 1;
break;
}
case _OVERFLOW:
{
printf("Overflow Error: Overflow range error.\n");
return 1;
break;
}
case _PLOSS:
{
printf("Precision Error: Partial loss of "
"significance.\n");
return 1;
break;
}
case _TLOSS:
{
printf("Precision Error: Total loss of "
"significance.\n");
return 1;
break;
}
case _UNDERFLOW:
{
printf("Underflow Error: The result is too small to "
"be represented.\n");
return 1;
break;
}
default:
{
printf("Unknown Error Occurred While Performing Math "
"Operation.\n");
return 1;
break;
}
}
}
else
return 0; /* non-error condition */
}
void main(void)
{
double x = -1.0e+307;
double y = -1.0e+307;
double z;
z = pow(x,y);
/*
Check for error conditions. _matherr() is automatically
called should there be a math related error.
*/
/*Note that errno is not set properly & _matherr() is called.*/
if (errno != 0)
printf("ERROR! Errno: %i\n",errno);
else
printf("pow( %e, %e ) = %f\n", x, y, z);
}
No error message is printed on overflow or underflow.
Keywords: kbbug KB167750