title: Performant way to check java.lang.Double for equality
body: <p>What is the most performant way to check double values for equality.</p>
  
  <p>I understand that</p>
  
  <pre><code>double a = 0.00023d;
  double b = 0.00029d;
  
  boolean eq = (a == b);
  </code></pre>
  
  <p>is slow.</p>
  
  <p>So I'm using</p>
  
  <pre><code>double epsilon = 0.00000001d;
  eq = Math.abs(a - b) &lt; epsilon;
  </code></pre>
  
  <hr>
  
  <p>The problem is that <code>Infinitest</code> is complaning about tests taking too much time. It's not a big deal (1 sec top), but it made me curious.</p>
  
  <p><strong>Additional info</strong></p>
  
  <p><code>a</code> is hard coded since it's the expected value, <code>b</code> is computed by</p>
  
  <pre><code>  // fyi: current = int, max = int
    public double getStatus()
    {
      double value = 0.0;
      if (current != 0 &amp;&amp; max != 0)
        value = ((double) current) / max;
      return value;
    }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>java.lang.Double does it that way</p>
  
  <pre><code>public boolean equals(Object obj) {
  return (obj instanceof Double)
         &amp;&amp; (doubleToLongBits(((Double)obj).value) ==
            doubleToLongBits(value));
  }
  </code></pre>
  
  <p>so one could assume that is the best practice.</p>