MATH_ERRNO, MATH_ERREXCEPT, math_errhandling
Min standard notice:
Header: <cmath>
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 C++11)
#define MATH_ERREXCEPT 2
(since C++11)
#define math_errhandling /*implementation defined*/
(since C++11)
# 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. std::rint vs std::nearbyint).
Before C++11, 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 <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
int main()
{
std::cout << "MATH_ERRNO is "
<< (math_errhandling & MATH_ERRNO ? "set" : "not set") << '\n'
<< "MATH_ERREXCEPT is "
<< (math_errhandling & MATH_ERREXCEPT ? "set" : "not set") << '\n';
std::feclearexcept(FE_ALL_EXCEPT);
errno = 0;
std::cout << "log(0) = " << std::log(0) << '\n';
if (errno == ERANGE)
std::cout << "errno = ERANGE (" << std::strerror(errno) << ")\n";
if (std::fetestexcept(FE_DIVBYZERO))
std::cout << "FE_DIVBYZERO (pole error) reported\n";
}