Incomparable NaN
When you divide by zero with double, take the square root of a negative number, overflow the maximum representable value etc. the result is a magic number called Double.NaN, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY. You
if ( Double.isNaN( d ) )
or with Double.isInfinite. You can’t test
if ( d == Double.NaN )
Because there are two different flavours of NAN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY You can’t directly compare == Double.NAN to check for NAN. However, you can directly compare == Double.NAN; However, you can use Double.isNaN or == to compare with Double.POSITIVE_INFINITY. There is a corresponding Float.NaN and Float.isNaN The theory is making NaN not equal to itself allows a quick and dirty way to test for a calculation going haywire.
if ( result != result )
{
System.out.println( "oops" );
}
In Groovy, Double.NaN == Double.NaN evaluates to true. This is probably a bug in Groovy