title: C++ warning: division of double by zero
body: <p><strong>Case 1:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      double d = 15.50;
      std::cout&lt;&lt;(d/0.0)&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>It compiles without any warnings and prints <code>inf</code>. OK, C++ can handle division by zero, (<a href="https://wandbox.org/permlink/qnpr8cM4W7rKlNid" rel="noreferrer">see it live</a>).</p>
  
  <p>But,</p>
  
  <p><strong>Case 2:</strong> </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      double d = 15.50;
      std::cout&lt;&lt;(d/0)&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>The compiler gives the following warning (<a href="https://wandbox.org/permlink/9cRSsWqewKxqN2CT" rel="noreferrer">see it live</a>):</p>
  
  <pre><code>warning: division by zero [-Wdiv-by-zero]
       std::cout&lt;&lt;(d/0)&lt;&lt;std::endl;
  </code></pre>
  
  <p>Why does the compiler give a warning in the second case? </p>
  
  <p>Is <code>0 != 0.0</code>?</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      if(0 == 0.0)
          std::cout&lt;&lt;"Same"&lt;&lt;std::endl;
      else
          std::cout&lt;&lt;"Not same"&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>Same
  </code></pre>