We have constexpr
functions since C++11, and they have been getting less restricted since with every new standard (14, 1z).
Yet, the most obvious functions in STL which could be made constexpr
, the cmath
/math.h
functions, still have no constexpr
version in any standard library implementation AFAIK.
Is this just in the backlog of the C++ standard, or is there any other reason why we still don't have constexpr
versions of these functions?
<cmath> is a standard library header of C++ which is extended from C header <math. h> and comes with namespace std . Since C++ 17, special mathematical functions were merged into the standard from TR1 and linear interpolation function (C++ 20) which were included inside <cmath> header.
h. math. h is a header file in the standard library of the C programming language designed for basic mathematical operations.
It hasn't been standardized yet. An initial proposal was submitted just last week, but only covering utility and linear operations and not any transcendental functions. Math is hard and floating-point math is complicated. For example, implementations don't allow overflows to infinity in constexpr
, but this isn't yet clearly standardized.
The compiler's constexpr
interpreter would have to special-case the math library interface, since unlike the rest of the standard library, it can't see its implementation.
GCC does offer constant evaluation of math functions as a nonconforming extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With