title: Testing for infinity in CUDA
body: <p>In a CUDA program, I recently switched from testing for inifinity using</p>
  
  <pre><code>return x==INFINITY || x==-INFINITY;
  </code></pre>
  
  <p>where <code>INFINITY</code> is from math.h, to</p>
  
  <pre><code>return !isfinite(x);
  </code></pre>
  
  <p>and was quite surprised to get different results. <a href="http://www.gnu.org/s/libc/manual/html_node/Infinity-and-NaN.html" rel="nofollow">gnu.org</a> suggests that they actually should behave similarly. Am I missing something? Is it not allowed to use <code>INFINITY</code> in a CUDA kernel?</p>
  
  <p><strong>Edit:</strong>
  I just discovered <code>isinf</code> and noticed that checking using</p>
  
  <pre><code>return isinf(x);
  </code></pre>
  
  <p>gives the same result as the INFINITY check. Why isn't 
  <code>isfinite(x)==!isinf(x)</code>?</p>