...
Explicitly check the range of each arithmetic operation and throw an ArithmeticException
on overflow. When performing operations on values of type int
, the arithmetic can be performed using variables of type long
. For performing arithmetic operations on numbers of type long
, the BigInteger
Class must be used.
Wiki Markup |
---|
According to the Java Tutorials \[[Tutorials 08|AA. Java References#Tutorials 08]\], Primitive Data Types: |
The
int
data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).The
long
data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided byint
.
Because a variable of the long
type is guaranteed to hold the result of an addition, subtraction or multiplication of values of type int
, the result can be assigned to such a variable, and if the result is in the integer range, we can simply downcast it to a value of type int
.
...