Java Reference
In-Depth Information
greater than or equal to
>=
less than
<
less than or equal to
<=
equal to
==
not equal to
!=
Both the relational and equality operators can be applied to the primitive
numeric types, with the usual mathematical interpretation applying.
Floating-point values follow normal ordering (1.0 is less than 0.0 is less
than positive infinity) except that NaN is an anomaly. All relational and
equality operators that test a number against NaN return
false
, except
!=
, which always returns
true
. This is true even if both values are NaN.
For example,
Double.NaN == Double.NaN
is always
false
. To test whether a value is NaN, use the type-specific
NaN
testers:
the
static
methods
and
Float.isNaN(float)
[2]
There is one other way to test for NaN: If
x
has a NaN value, then
x != x
is true. This is interesting
but very obscure, so you should use the methods instead.