MATH_ERRNO, MATH_ERREXCEPT, math_errhandling
Header: <math.h>
The macro constant math_errhandling expands to an expression of type int that is either equal to MATH_ERRNO, or equal to MATH_ERREXCEPT, or equal to their bitwise OR (MATH_ERRNO | MATH_ERREXCEPT).
# Declarations
#define MATH_ERRNO 1
(since C99)
#define MATH_ERREXCEPT 2
(since C99)
#define math_errhandling /*implementation defined*/
(since C99)
# Notes
Whether FE_INEXACT is raised by the mathematical library functions is unspecified in general, but may be explicitly specified in the description of the function (e.g. rint vs nearbyint).
Before C99, floating-point exceptions were not specified, EDOM was required for any domain error, ERANGE was required for overflows and implementation-defined for underflows.
# Example
#include <stdio.h>
#include <fenv.h>
#include <math.h>
#include <errno.h>
#pragma STDC FENV_ACCESS ON
int main(void)
{
printf("MATH_ERRNO is %s\n", math_errhandling & MATH_ERRNO ? "set" : "not set");
printf("MATH_ERREXCEPT is %s\n",
math_errhandling & MATH_ERREXCEPT ? "set" : "not set");
feclearexcept(FE_ALL_EXCEPT);
errno = 0;
printf("log(0) = %f\n", log(0));
if(errno == ERANGE)
perror("errno == ERANGE");
if(fetestexcept(FE_DIVBYZERO))
puts("FE_DIVBYZERO (pole error) reported");
}