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.
发布评论
评论(1)
作为一般规则,数学功能设置
errno
被认为是过时的功能,因为IEEE无限,NAN和浮点异常标志被认为是报告数学计算错误的出色方法。这似乎并未在标准中的任何地方明确说明,但通常请参见 7.12.1误差条件的处理[数学功能] ,尤其是对Math_errhandling的讨论
erfc(x)
将零变为零,erf(x)
将其迅速随着x的增加而迅速;erfc(10)
已经按照2e-45
的顺序。在IEEE 754的术语中,描述erfcf(flt_max)和
erff(flt_max)
的结果的最精确方法是em>零或一个。但是,即使在符合附件F的实施中,也不需要图书馆函数报告不确定性( f.10p8 )。一个数学结果非常接近零,以至于不能准确表示它是 underflow 条件(7.12.1p6)。底流条件可能但不需要,将Errno设置为Erange。
一个数学结果非常接近一个,以至于不能准确地表示它是7.12.1中所述的任何错误条件,因此不是 要通过设置errno。
进行报告
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 ofmath_errhandling
.erfc(x)
goes to zero, anderf(x)
to one, quite rapidly as x increases;erfc(10)
is already on the order of2e-45
. The most precise way to describe the result oferfcf(FLT_MAX)
and oferff(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).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.
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.