dcsimg

What are Double.NaN/Float.NaN (Not-a-Number) and when would I need to use it?

John Mitchell

NaN is a special value that represents the case where the result of certain operations doesn't have an actual answer such as dividing zero by zero. So, you would use NaN wherever you might need to know that the result of an operation produced a NaN.

For more information, check out section 4.2.3 of The Java Language Specification.