Difference Between HUGE_VALF and INFINITY Constants

我怕爱的太早我们不能终老 提交于 2019-12-10 05:28:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20557691/difference-between-huge-valf-and-infinity-constants

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!