In Java, what does NaN mean?

David picture David · Apr 11, 2010 · Viewed 281k times · Source

I have a program that tries to shrink a double down to a desired number. The output I get is NaN.

What does NaN mean in Java?

Answer

KennyDeriemaeker picture KennyDeriemaeker · Apr 11, 2010

Taken from this page:

"NaN" stands for "not a number". "Nan" is produced if a floating point operation has some input parameters that cause the operation to produce some undefined result. For example, 0.0 divided by 0.0 is arithmetically undefined. Taking the square root of a negative number is also undefined.