不确定结果的STD ::复杂的行为
on (公开可访问的草稿)C ++ 17标准,它说调用具有数学不确定结果的函数是不确定的行为。例如,
#include <iostream>
#include <complex>
int main() {
std::cout << std::complex<double>(0., 0.) / std::complex<double>(0., 0.);
return 0;
}
在clang 7上打印(-nan,-nan)
。
零的float部门通常是不确定的行为,但是实现可能遵循IEEE-754语义(C标准中的附件F),并提及在某些C ++标准中传递,但我不确定这一点)。因此,零的浮动除法被定义为std :: numeric_limits&lt; double&gt; :: is_iec559
是正确的实现。
这是一个语言律师问题,因此我不确定为什么这些评论沿着“不确定行为可以做任何事情”的道路走了。当然,但是对于遵循IEEE-754的实现,未指定(或认为实施定义)的结果的标准缺陷?
On page 1052 of (the openly accessible draft of) the C++17 standard, it says that calling a function which has a mathematically undefined result is undefined behavior. For example,
#include <iostream>
#include <complex>
int main() {
std::cout << std::complex<double>(0., 0.) / std::complex<double>(0., 0.);
return 0;
}
prints (-nan,-nan)
on clang 7.
Float division by zero is undefined behavior in general, but implementations may follow IEEE-754 semantics (Annex F in the C standard, and mentioned in passing in some of the C++ standard, but I'm not sure on that point). So float division by zero is defined to be NaN in implementations in which std::numeric_limits<double>::is_iec559
is true.
This is a language lawyer question, so I'm not sure why the comments are going down the path of "undefined behavior can do anything". Of course, but is it a defect in the standard that the results are not specified (or considered implementation-defined) for implementations that follow IEEE-754?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论