title: Confusing long vs double behavior in Java
body: <p>Here is a small method that shows type-casting to double works, but plain longs do not.</p>
  
  <pre><code>public void test() {
      long s = Long.MIN_VALUE;
      long e = Long.MAX_VALUE;
      System.out.println((double)e-(double)s);
      System.out.println(e-s);
      System.out.println(Double.SIZE);
      System.out.println(Long.SIZE);
  }
  </code></pre>
  
  <p>And the output from the above method is:   </p>
  
  <pre><code>1.8446744073709552E19
  -1
  64
  64
  </code></pre>
  
  <p>So the question is if both double and long are 64-bit numbers in Java, then why does type-casting to double gives a better result?</p>
  
  <p><strong>Follow-up question</strong>:</p>
  
  <p>In Java, I want to divide the whole range of long (from -2^63 to 2^63-1) into 10,000 equal ranges. How can I do the same? (some code would be really helpful).</p>