为什么ERF函数没有范围错误?

发布于 2025-02-07 13:31:21 字数 590 浏览 0 评论 0 原文

erfcf(flt_max)生产 0.0F 和SETS errno to erange

erff(flt_max)产生 1.0f ,并且未设置 errno erange

在这两种情况下,返回的结果与“真实结果”不同(即以无限精度获得)。

为什么 erange 仅针对 ERFCF 设置?


C11措辞(添加了重点):

同样,如果由于极端幅度。。。。

C2X措辞(添加了强调):

同样,仅当结果溢出或下面流体时,就会发生A 范围误差。每个功能的描述列出了任何必需的范围错误;实现可能会定义其他范围错误,只要此类错误与函数的数学定义一致,并且是溢出或下流的结果。所需或实施定义的范围错误应分别按照本第一项规定报告。

The erfcf(FLT_MAX) produces 0.0f and sets errno to ERANGE.

The erff(FLT_MAX) produces 1.0f and does not set errno to ERANGE.

In both cases returned results differ from the "true results" (i.e. obtained with infinite precision).

Why ERANGE is set only for erfcf?


C11 wording (emphasis added):

Likewise, a range error occurs if the mathematical result of the function cannot be represented in an object of the specified type, due to extreme magnitude.

C2X wording (emphasis added):

Likewise, a range error occurs if and only if the result overflows or underflows, as defined below. The description of each function lists any required range errors; an implementation may define additional range errors, provided that such errors are consistent with the mathematical definition of the function and are the result of either overflow or underflow. Range errors that are required or implementation-defined shall or may be reported, as specified in this subclause, respectively.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小苏打饼 2025-02-14 13:31:21
  1. 作为一般规则,数学功能设置 errno 被认为是过时的功能,因为IEEE无限,NAN和浮点异常标志被认为是报告数学计算错误的出色方法。这似乎并未在标准中的任何地方明确说明,但通常请参见 7.12.1误差条件的处理[数学功能] ,尤其是对 Math_errhandling的讨论

  2. erfc(x)将零变为零, erf(x) 将其迅速随着x的增加而迅速; erfc(10)已经按照 2e-45 的顺序。在IEEE 754的术语中,描述 erfcf(flt_max)和 erff(flt_max)的结果的最精确方法是em>零或一个。但是,即使在符合附件F的实施中,也不需要图书馆函数报告不确定性( f.10p8 )。


  3. 一个数学结果非常接近零,以至于不能准确表示它是 underflow 条件(7.12.1p6)。底流条件可能但不需要,将Errno设置为Erange。

  4. 一个数学结果非常接近一个,以至于不能准确地表示它是7.12.1中所述的任何错误条件,因此不是 要通过设置errno。

    进行报告

  1. As a general rule, math functions setting errno is considered an obsolescent feature, because IEEE infinities, NaNs, and floating point exception flags are considered a superior method of reporting errors for mathematical calculations. This does not seem to be stated explicitly anywhere in the Standard, but see generally 7.12.1 Treatment of error conditions [in math functions], particularly the discussion of math_errhandling.

  2. erfc(x) goes to zero, and erf(x) to one, quite rapidly as x increases; erfc(10) is already on the order of 2e-45. The most precise way to describe the result of erfcf(FLT_MAX) and of erff(FLT_MAX), in the terminology of IEEE 754, is as an inexact zero or one, respectively. However, even in an implementation conforming to Annex F, library functions are not required to report inexactness (F.10p8).

  3. A mathematical result that is so close to zero that it cannot be represented exactly is an underflow condition (7.12.1p6). Underflow conditions may, but are not required to, set errno to ERANGE.

  4. A mathematical result that is so close to one that it cannot be represented exactly is not considered to be any of the error conditions described in 7.12.1, and therefore is not to be reported by setting errno.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文