The type of each of the operands of a numerical comparison operator must be a
primitive numeric type, or a compile-time error occurs. Binary numeric promotion
is performed on the operands (§5.6.2). If the promoted type of the operands is int
or long
, then signed integer comparison is performed; if this promoted type is
float
or double
, then floating-point comparison is performed.
The result of a floating-point comparison, as determined by the specification of the IEEE 754 standard, is:
false
.
-0.0<0.0
is false
, for example, but -0.0<=0.0
is true
. (Note, however, that the methods Math.min
(§20.11.27, §20.11.28) and Math.max
(§20.11.31, §20.11.32) 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:
<
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
.
<=
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
.
>
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
.
>=
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
.