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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With