Difference Between HUGE_VALF and INFINITY Constants

旧街凉风 提交于 2019-12-05 10:20:31

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.

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