macro
<cmath> <ctgmath>

math_errhandling

int
Error handling
Expands to an expression that identifies the error handling mechanism employed by the functions in the <cmath> header:

constantvaluedescription
MATH_ERRNO1errno is used to signal errors:
- On domain error: errno is set to EDOM.
- On range error (including pole error, overflow, and possibly underflow): errno is set to ERANGE.
MATH_ERREXCEPT2The proper C exception is raised:
- On domain error: FE_INVALID is raised.
- On pole error: FE_DIVBYZERO is raised.
- On overflow: FE_OVERFLOW is raised.
- On underflow: FE_UNDERFLOW may be raised.
MATH_ERRNO|MATH_ERREXCEPT3Both of the above

Both MATH_ERRNO and MATH_ERREXCEPT are macro constant expressions defined in <cmath> as 1 and 2 respectivelly.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* math_errhandling example */ #include <stdio.h> /* printf */ #include <math.h> /* math_errhandling */ #include <errno.h> /* errno, EDOM */ #include <fenv.h> /* feclearexcept, fetestexcept, FE_ALL_EXCEPT, FE_INVALID */ #pragma STDC FENV_ACCESS on int main () { errno = 0; if (math_errhandling & MATH_ERREXCEPT) feclearexcept(FE_ALL_EXCEPT); printf ("Error handling: %d",math_errhandling); sqrt (-1); if (math_errhandling & MATH_ERRNO) { if (errno==EDOM) printf("errno set to EDOM\n"); } if (math_errhandling &MATH_ERREXCEPT) { if (fetestexcept(FE_INVALID)) printf("FE_INVALID raised\n"); } return 0; }

Possible output:
 Error handling: 3 errno set to EDOM FE_INVALID raised 


Data races

Libraries that support multi-threading shall implement errno and/or floating-point exception state in a per-thread basis: With each thread having its own local errno and floating-point state.
This is a requirement for libraries compliant with C11 and C++11 standards.