Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing for infinity in CUDA

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)?

like image 612
hannes Avatar asked Dec 03 '10 22:12

hannes


1 Answers

isfinite(a) is the same as !isnan(a) && !isinf(a). If x is NaN, then both isfinite(x) and isinf(x) are false.

like image 82
Stephen Canon Avatar answered Nov 14 '22 23:11

Stephen Canon