In a CUDA program, I recently switched from testing for inifinity using
return x==INFINITY || x==-INFINITY;
where INFINITY
is from math.h, to
return !isfinite(x);
and was quite surprised to get different results. gnu.org suggests that they actually should behave similarly. Am I missing something? Is it not allowed to use INFINITY
in a CUDA kernel?
Edit:
I just discovered isinf
and noticed that checking using
return isinf(x);
gives the same result as the INFINITY check. Why isn't
isfinite(x)==!isinf(x)
?
isfinite(a)
is the same as !isnan(a) && !isinf(a)
. If x
is NaN, then both isfinite(x)
and isinf(x)
are false.
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