As of C++20 std::isnan is not constexpr.
Is there a technical reason for this?
All I can think of is that it is in "C header" so nobody bothered to fix it (<limits>
functions dealing with floats are constexpr, but unfortunately numeric_limits
does not contain isnan check).
The answer is basically "Because the proposal hasn't been merged into the standard yet"
P0533 Proposes what you are asking, and it did not make it into C++20.
One of the holdups is that perhaps this proposal is a little big... some of the functions in <cmath>
or <cstdlib>
are allowed to set global error codes, which complicates the whole "constexpr
all the things" proposal*
I don't think there should be any issue with these classification functions; std::isnan
and its sibling std::fpclassify
are defined to behave identically to the C macros isnan
and fpclassify
respectively. This will need to change slightly.
*(aside: p2043 "Don't constexpr
all the things" is tangentially relevant here, but it's only talking about metaprogramming)
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