title: Comparing floating point number to zero
body: <p>The C++ FAQ lite <a href="http://www.parashift.com/c++-faq/floating-point-arith.html" rel="noreferrer">&quot;[29.17] Why doesn't my floating-point comparison work?&quot;</a> recommends this equality test:</p>
  <pre><code>#include &lt;cmath&gt;  /* for std::abs(double) */
  
  inline bool isEqual(double x, double y)
  {
    const double epsilon = /* some small number such as 1e-5 */;
    return std::abs(x - y) &lt;= epsilon * std::abs(x);
    // see Knuth section 4.2.2 pages 217-218
  }
  </code></pre>
  <ol>
  <li>Is it correct, that this implies that the only numbers which are equal to zero are <code>+0</code> and <code>-0</code>?</li>
  <li>Should one use this function also when testing for zero or rather a test like <code>|x| &lt; epsilon</code>?</li>
  </ol>
  <p><strong>Update</strong></p>
  <p>As pointed out by Daniel Daranas the function should probably better be called <code>isNearlyEqual</code> (which is the case I care about).</p>
  <p>Someone pointed out <a href="https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/" rel="noreferrer">&quot;Comparing Floating Point Numbers&quot;</a>, which I want to share more prominently.</p>