Primitive double value equal depends on magnitude?
<p>I have to check to see whether two double values are equal including magnitude and precision. I encounter a weird scenario where primitive double equals check is not consistent and depend on magnitude of value. </p>

<p>Java version i've used:</p>

<pre><code>java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
</code></pre>

<p>My code:</p>

<pre><code>public class Test{
     public static void main(String args[]) throws Exception{
         String val1 = "15.999999999999999";
         String val2 = "16";
         String val3 = "16.999999999999999";
         String val4 = "17";
         double d1 = Double.parseDouble(val1);
         double d2 = Double.parseDouble(val2);
         double d3 = Double.parseDouble(val3);
         double d4 = Double.parseDouble(val4);
         System.out.println(val1 + "=" + val2 + "? ===&gt;" + (d1==d2));
         System.out.println(val3 + "=" + val4 + "? ===&gt;" + (d3==d4));
     }
}
</code></pre>

<p>Output:</p>

<pre><code>15.999999999999999=16? ===&gt;false
16.999999999999999=17? ===&gt;true
</code></pre>
