Question:
What does NaN mean in java?
Answer:
Not A Number
Here are a few examples on how to generate (trigger) a NaN:
Here are a few examples on how to generate (trigger) a NaN:
Code:
public class NaN { public static void main(String[] args) { Double d1 = 0d/0d; System.out.println("d1: " + d1); Double d2 = Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY; System.out.println("d2: " + d2); Double d3 = 0d * Double.POSITIVE_INFINITY; System.out.println("d3: " + d3); Double d4 = Math.pow(1, Double.POSITIVE_INFINITY); System.out.println("d4: " + d4); Double d5 = Double.POSITIVE_INFINITY + Double.NEGATIVE_INFINITY; System.out.println("d5: " + d5); Float f1 = Float.POSITIVE_INFINITY - Float.POSITIVE_INFINITY; System.out.println("f1: " + f1); } }
Output:
$ java NaN d1: NaN d2: NaN d3: NaN d4: NaN d5: NaN f1: NaN