other versions
- wheezy 3.44-1
- jessie 3.74-1
- jessie-backports 4.10-2~bpo8+1
- testing 4.10-2
- unstable 4.10-2
MATH_ERROR(7) | Linux Programmer's Manual | MATH_ERROR(7) |
NAME¶
math_error - detecting errors from mathematical functionsSYNOPSIS¶
#include <math.h> #include <errno.h> #include <fenv.h>
DESCRIPTION¶
When an error occurs, most library functions indicate this fact by returning a special value (e.g., -1 or NULL). Because they typically return a floating-point number, the mathematical functions declared in <math.h> indicate an error using other mechanisms. There are two error-reporting mechanisms: the older one sets errno; the newer one uses the floating-point exception mechanism (the use of feclearexcept(3) and fetestexcept(3), as outlined below) described in fenv(3).feclearexcept(FE_ALL_EXCEPT);
before calling a mathematical function.
fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
then an error occurred in the mathematical function.
Domain Error¶
A domain error occurs when a mathematical function is supplied with an argument whose value falls outside the domain for which the function is defined (e.g., giving a negative argument to log(3)). When a domain error occurs, math functions commonly return a NaN (though some functions return a different value in this case); errno is set to EDOM, and an "invalid" (FE_INVALID) floating-point exception is raised.Pole Error¶
A pole error occurs when the mathematical result of a function is an exact infinity (e.g., the logarithm of 0 is negative infinity). When a pole error occurs, the function returns the (signed) value HUGE_VAL, HUGE_VALF, or HUGE_VALL, depending on whether the function result type is double, float, or long double. The sign of the result is that which is mathematically correct for the function. errno is set to ERANGE, and a "divide-by-zero" (FE_DIVBYZERO) floating-point exception is raised.Range Error¶
A range error occurs when the magnitude of the function result means that it cannot be represented in the result type of the function. The return value of the function depends on whether the range error was an overflow or an underflow.NOTES¶
The math_errhandling identifier specified by C99 and POSIX.1-2001 is not supported by glibc. This identifier is supposed to indicate which of the two error-notification mechanisms (errno, exceptions retrievable via fettestexcept(3)) is in use. The standards require that at least one be in use, but permit both to be available. The current (version 2.8) situation under glibc is messy. Most (but not all) functions raise exceptions on errors. Some also set errno. A few functions set errno, but don't raise an exception. A very few functions do neither. See the individual manual pages for details.double x, r; if (isnan(x) || islessequal(x, 0)) { /* Deal with NaN / pole error / domain error */ } r = log(x);
The discussion on this page does not apply to the complex mathematical functions (i.e., those declared by <complex.h>), which in general are not required to return errors by C99 and POSIX.1-2001.
SEE ALSO¶
gcc(1), errno(3), fenv(3), fpclassify(3), INFINITY(3), isgreater(3), matherr(3), nan(3)COLOPHON¶
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.2008-08-11 | Linux |