不确定结果的STD ::复杂的行为

发布于 2025-01-22 09:38:45 字数 721 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文