title: At a certain point, does adding a large integer to a long integer well below its limit in Java cause problems?
body: <p>For example, adding <em>4.0E16</em> or *4*Math.pow(10, 16)* to: </p>
  
  <blockquote>
    <p>5,390,195,186,705,543</p>
  </blockquote>
  
  <p>The result should be: </p>
  
  <blockquote>
    <p>45,390,195,186,705,543</p>
  </blockquote>
  
  <p>but the following code returns </p>
  
  <blockquote>
    <p>45,390,195,186,705,544</p>
  </blockquote>
  
  <p>adding 1 to the least significant digit (which shouldn't be happening).</p>
  
  <p>From what I've researched online the upper limit of long is: </p>
  
  <blockquote>
    <p>9,223,372,036,854,775,807</p>
  </blockquote>
  
  <p>but the example I've given has not exceeded that limit yet.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>int [] digits = new digits[] {6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3};
  long sum = new Long(0);
  int k = digits.length-1;
  
  for(int j = digits.length-1; j&gt;=0; j--)
  {
  
      sum = (long) (sum +  (long)digits[j]*Math.pow(10, k-j));
  }
  </code></pre>