title: How does C++ deal with NAN? Is there a standard way or is compiler dependent?
body: <p>In a program that needs to process sin(x)/x function, I encountered NAN problem, I simplified the problem in the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  
  int main()
  {
      std::cout.precision(15);
  
      //This line compiles and run in g++, but does not compile in Visual Studio 2013
      std::cout &lt;&lt; 0.0/0.0 &lt;&lt; std::endl;
  
      //This line compiles and run in both g++ and VS2013
      std::cout &lt;&lt; std::sin(0.0)/0.0 &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>In g++, the output is: -nan   -nan, in VS2013, the output is: -1.IND, because the first line does not compile so I commented it out.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>What does this '-1.IND' mean?</p></li>
  <li><p>It seems NAN processing is compiler dependent, should this be standardized in C++? Why?</p></li>
  <li><p>I used this hack to deal with this problem:</p>
  
  <pre><code>double sinc(double x)
  {
      if(x == 0.0)
          return 1.0;
      return std::sin(x)/x;
  }
  </code></pre></li>
  </ol>
  
  <p>Is this the right way?</p>
  
  <p>EDIT: another question, 4. why VS2013 deal with 0.0/0.0 and sin(0.0)/0.0 differently?</p>