I was looking at the openjdk-1.7.0_25
source code and I have seen this method:
/**
* Returns {@code true} if the specified number is a
* Not-a-Num
Simple.. Nan
is always != NaN
, these values are not equal to anything. See this:
As has already been described, NaN is unordered, so a numeric comparison operation involving one or two NaNs returns false and any != comparison involving NaN returns true, including x!=x when x is NaN.
So testing if v != v
is sufficient to tell whether the value
is NaN
or not.