title: Java - comparison of positive and negative zeros
body: <p>Why is Java inconsistent in comparing -0.0 and +0.0?  What is the Java standard method for comparing numbers to account for -0/+0?</p>
  
  <p>I have encountered this particular bugaboo:</p>
  
  <pre><code>public class ZeroCompare {
      public static void main(String[] args) {
          if ( 0.0 == -0.0 ) {
              System.out.println("== --&gt; same");
          } else {
              System.out.println("== --&gt; different");
          }
  
          if ( new Double(0.0).equals( -0.0 ) ) {
              System.out.println("equals --&gt; same");
          } else {
              System.out.println("equals --&gt; different");
          }
      }
  }
  </code></pre>
  
  <p>It prints the following:</p>
  
  <pre><code>== --&gt; same
  equals --&gt; different
  </code></pre>
  
  <p>I strongly dislike the fact that how you compare these two values affects the outcome and I'd love for an explanation.</p>