[英]Guarantees about C++ infinity()
Since <cmath>
originates from the C standard but <limits>
is native C++, provided that numeric_limits<double>::has_infinity()
is true ( edit: and also that numeric_limits<double>::is_iec559()
is true), does the C++ (98/11/14) standard guarantees anywhere that the followings are always true? 由于
<cmath>
起源于C标准,但<limits>
是本机C ++,因此,假设numeric_limits<double>::has_infinity()
为true( 编辑:并且numeric_limits<double>::is_iec559()
为true), C ++(98/11/14)标准在任何地方都保证以下内容总是正确的? The references on MSDN and cplusplus.com don't seem to have offered any useful explanation. MSDN和cplusplus.com上的参考文献似乎没有提供任何有用的解释。
isinf(numeric_limits<double>::infinity())
x < numeric_limits<double>::infinity()
given that isfinite(x)
is true isfinite(x)
为true, isfinite(x)
x < numeric_limits<double>::infinity()
!( numeric_limits<double>::infinity()<numeric_limits<double>::infinity() )
I ask this question because I want to write a function of the form f(double x, double upper_bound)
, where the function body will branch according to whether x
breaches the upper bound or not. 我问这个问题是因为我想编写一个形式为
f(double x, double upper_bound)
的函数,其中函数体将根据x
是否违反上限而分支。
There is little sait on infinity()
in the C++11 standard. 在C ++ 11标准中,对
infinity()
看法很少。 Just that it's the representation of positive infinity . 仅仅是正无穷大的表示 。
isinf()
belongs in C++ to <cmath>
which wraps the c math library, and C11 says: The isinf macro returns a nonzero value if and only if its argument has an infinite value. isinf()
在C ++中属于<cmath>
,后者包装了c数学库,C11说: isinf宏仅在其参数具有无限值时返回非零值。 Hence, you can deduce from that definition that isinf(numeric_limits<double>::infinity())
should be granted. 因此,您可以从该定义推断出应授予
isinf(numeric_limits<double>::infinity())
。
No formal guarantee is given in the standard itself, on the fact that every finite x should be smaler than infinity. 标准本身没有形式上的保证,因为每个有限的x应该比无穷小。 However, if
numeric_limits<double>::is_iec559
is true, then you can base your assumption on the iec 559 aka Ieee 754 standard, which ensures positive infinity is larger than everything except itself . 但是,如果
numeric_limits<double>::is_iec559
为true,则可以基于iec 559(也称为Ieee 754)标准进行假设,该标准可确保正无穷大除其自身以外的所有值都大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.