问题描述
在OpenCL中,有两个浮点数学常量表示无穷大。其中之一就是 INFINITY
。另外, HUGE_VALF
,评估为无穷大。 这两者有什么区别?这是什么意思,评估无穷?
HUGE_VALF
是一个传统名称,允许不支持无穷的浮点系统。例如,C标准指定在某些溢出情况下返回 HUGE_VALF
。当C实现不支持无穷时, HUGE_VALF
将是最大的可表示值。当一个实现支持无限时, HUGE_VALF
将是无穷的。 C标准仍然允许这样做,而且我认为有一些实现仍然不支持无穷。
OpenCL使用IEEE 754(或多或少),所以它有无穷大,所以
HUGE_VALF
是无穷大。通过定义 HUGE_VALF
,OpenCL有助于支持旧C代码移植到OpenCL。 关于 HUGE_VALF
计算结果为+ infinity但是 INFINITY
是浮点类型的常量表达式,表示正或无符号无穷大,I会怀疑这是否意图允许一些运行时准备 HUGE_VALF
(例如,将其表示为 1./0。
)。但是,也表示 HUGE_VALF
是一个积极的浮点常量表达式。在余额上,这让我觉得措辞简单一点,而且 HUGE_VALF
和 INFINITY
是等效的。
In OpenCL, there are two floating point math constants that represent infinity. One of them is simply INFINITY
. The other, HUGE_VALF
, "evaluates to" infinity.
What is the difference between these two? What does it mean to "evaluate to" infinity?
HUGE_VALF
is a legacy name that allows for floating-point systems that did not support infinities. For example, the C standard specifies that HUGE_VALF
be returned in certain overflow cases. When a C implementation did not support infinities, HUGE_VALF
would be the largest representable value. When an implementation did support infinities, HUGE_VALF
would be infinity. The C standard still allows this, and I suppose there are some implementations around that still do not support infinities.
OpenCL uses IEEE 754 (more or less), so it does have infinities, so HUGE_VALF
is infinity. By defining HUGE_VALF
, OpenCL helps to support old C code being ported to OpenCL.
Regarding the wording that says "HUGE_VALF
evaluates to +infinity" but INFINITY
is "A constant expression of type float representing positive or unsigned infinity", I would wonder whether that is intended to allow for some run-time preparation of HUGE_VALF
(e.g., expressing it as 1./0.
). However, the documentation also says that HUGE_VALF
is "A positive float constant expression." On the balance, that makes me think the wording is simply a bit sloppy, and that HUGE_VALF
and INFINITY
are equivalent.
这篇关于HUGE_VALF和INFINITY常量之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!