Pitfalls+and+Surprises

Largest acceptable integer is 2147483647, that is, 231 – 1. This number is also the value of the expression Integer.MAX_VALUE.

Smallest acceptable integer is the value — namely, -2147483648 — of the expressionInteger.MIN_VALUE

If you perform a calculation whose exact result lies outside this range, then the computer experiences what is called an //overflow// condition, and extremely strange things can happen.

Overflow Condition are: > > >> >>
 * the sum of two positive numbers yielding a negative result;
 * the product of two fairly large positive numbers yielding zero as the result;
 * the sum of two numbers that are a long way from zero in the negative direction yielding zero as the result.
 * the product of a positive and a negative number yielding a positive result — for example,65536 * -65535 ;
 * the product of two negative numbers yielding a negative result — for example,<span class="code nowrap" style="color: #0000ff; font-family: 'Courier New',Courier,monospace; white-space: nowrap;">-64000 * -64000 ;

<span style="color: #000000; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;">On the positive side of <span class="code nowrap" style="color: #0000ff; font-family: 'Courier New',Courier,monospace; white-space: nowrap;">0, it extends from 2-1074 through (2 - 2-52) * 21023, that is, approximately <span style="color: #000000; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left: 3em;">from 4.9406564584124654 * 10-324 through 1.7976931348623158 * 10308.

<span style="color: #000000; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left: 3em;"> After it surpasses the largest number that can be stored as a floating point <span class="code nowrap" style="color: #0000ff; font-family: 'Courier New',Courier,monospace; white-space: nowrap;">double. So an overflow condition occurs, and the "catch-all" answer of <span class="code nowrap" style="color: #0000ff; font-family: 'Courier New',Courier,monospace; white-space: nowrap;">Infinity is reported.

<span style="color: #000000; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left: 3em;"> it is the programmers' responsibility to prepare for the possibility that calculations may provoke overflow or underflow conditions by including suitable checks in their code that, if triggered, will cause warnings to be issued.