Go to the Java Language Specification link I provided earlier and look for �4.2.3 and �4.2.4.
You can get NaN from various operations; 0f / 0f or Math.sqrt(-1) will both give Nan. In the case of the sqrt method (which is actually written in C or C++) there is something in it which in Java would be like this:That acts as a guard against trying to calculate the square root of 0 (which is 0) or of a negative number which is not-a-number.
In the Float API documentation it says that NaN is not ordered; that becomes obvious when we try some arithmetic.
2 * 0 = 0 3 * 0 = 0 ∴ 2 * 0 = 3 * 0 Multiply both sides by 0 / 0, which is Nan; that gets rid of the zeroes ∴ 2 = 3
The only way you can get out of this nonsense result is saying that NaN is not equal to itself.