title: How to check for inf (and | or) NaN in a double variable
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  template&lt;class T&gt;
  bool IsNaN(T t)
  {
      return t != t;
  }
  
  int main(int argc, char**argv)
  {
      double d1, d2;
      sscanf(argv[1], "%f", &amp;d1);
      sscanf(argv[2], "%f", &amp;d2);
  
      double dRes = d1/d2;
  
      cout &lt;&lt; "dRes = " &lt;&lt; dRes &lt;&lt; "\n";
  
      if(IsNaN(dRes))
          cout &lt;&lt; "Is NaN\n";
      else
          cout &lt;&lt; "Not NaN\n";
  
  }
  </code></pre>
  
  <p>Couple of questions:</p>
  
  <ol>
  <li>When I pass 0 and 0 as arguments, it outputs <code>dRes = inf</code>. But I was expecting <code>dRes = NaN</code> or something like that.</li>
  <li>Is NaN representable in double variables? For that matter, any variable?</li>
  <li>When I changed the data type of d1,d2,dRes to int and passed 0 and 0, I got a <code>Floating exception</code>. What is the difference?</li>
  <li>How to check if a variable's value is equal to <code>inf</code>?</li>
  </ol>