Reputation: 27455
The JLS 8, chapt 15.21 specifies two concepts named floating point equality test
and integer equality test
as follows:
If the promoted type of the operands is int or long, then an integer equality test is performed.
If the promoted type is float or double, then a floating-point equality test is performed.
Where floating point's defined as follows:
Floating-point equality testing is performed in accordance with the rules of the IEEE 754 standard:
So, we can refer to IEEE 754 in order to describe behavior with floating-point equality. But what about int
s? Where the JLS specifies how it performs integer equality test?
Upvotes: 0
Views: 57
Reputation: 106508
Since int
and all other integral types are signed two's complement in Java, you shouldn't worry about having two different ways of representing 0.
Since you were looking for a reference, the JLS §4.2. provides one:
If an integer operator other than a shift operator has at least one operand of type long, then the operation is carried out using 64-bit precision, and the result of the numerical operator is of type long. If the other operand is not long, it is first widened (§5.1.5) to type long by numeric promotion (§5.6).
Otherwise, the operation is carried out using 32-bit precision, and the result of the numerical operator is of type int. If either operand is not an int, it is first widened to type int by numeric promotion.
Upvotes: 2