[英]Why is std::isnan not constexpr?
As of C++20 std::isnan is not constexpr.从 C++20 开始,std::isnan 不是 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).我能想到的只是它在“C 标头”中,所以没有人费心去修复它(处理浮点数的<limits>
函数是 constexpr,但不幸的是numeric_limits
不包含 isnan 检查)。
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. P0533提出你的要求,但它没有进入 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 *其中一个问题是,也许这个提议有点大...... <cmath>
或<cstdlib>
中的一些函数被允许设置全局错误代码,这使得整个“ constexpr
all the things”提议变得复杂*
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. std::isnan
及其兄弟std::fpclassify
被定义为分别与 C 宏isnan
和fpclassify
相同。 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) * (旁白: p2043 “不要constexpr
所有的东西都解释”在这里是切线相关的,但它只是在谈论元编程)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.