Java Reference
In-Depth Information
Note that binary numeric promotion performs value set conversion (§
5.1.13
) and may
perform unboxing conversion (§
5.1.8
).
If the promoted type of the operands is
int
or
long
, then signed integer comparison is per-
formed.
If the promoted type is
float
or
double
, then floating-point comparison is performed.
Comparison is carried out accurately on floating-point values, no matter what value sets
their representing values were drawn from.
The result of a floating-point comparison, as determined by the specification of the IEEE
754 standard, is:
• If either operand is NaN, then the result is false.
• All values other than NaN are ordered, with negative infinity less than all finite
values, and positive infinity greater than all finite values.
• Positive zero and negative zero are considered equal.
For example,
-0.0<0.0
is
false
, but
-0.0<=0.0
is
true
.
Note, however, that the methods
Math.min
and
Math.max
treat negative zero as
being strictly smaller than positive zero.
Subject to these considerations for floating-point numbers, the following rules then hold
for integer operands or for floating-point operands other than NaN:
• The value produced by the
<
operator is
true
if the value of the left-hand operand is
less than the value of the right-hand operand, and otherwise is
false
.
• The value produced by the
<=
operator is
true
if the value of the left-hand operand
is less than or equal to the value of the right-hand operand, and otherwise is
false
.
• The value produced by the
>
operator is
true
if the value of the left-hand operand is
greater than the value of the right-hand operand, and otherwise is
false
.
• The value produced by the
>=
operator is
true
if the value of the left-hand operand
is greater than or equal to the value of the right-hand operand, and otherwise is
false
.
15.20.2. Type Comparison Operator
instanceof
The type of the
RelationalExpression
operand of the
instanceof
operator must be a reference
type or the null type; otherwise, a compile-time error occurs.