GenerateNaN.java
--D. Thiebaut (talk) 10:12, 26 April 2017 (EDT)
GenerateNaN.java
Source Code
/* */ import java.util.*; import static java.lang.Double.NaN; import static java.lang.Double.POSITIVE_INFINITY; import static java.lang.Double.NEGATIVE_INFINITY; public class GenerateNaN { public static void main(String args[]) { double[] allNaNs = { 0D / 0D, POSITIVE_INFINITY / POSITIVE_INFINITY, POSITIVE_INFINITY / NEGATIVE_INFINITY, NEGATIVE_INFINITY / POSITIVE_INFINITY, NEGATIVE_INFINITY / NEGATIVE_INFINITY, 0 * POSITIVE_INFINITY, 0 * NEGATIVE_INFINITY, Math.pow(1, POSITIVE_INFINITY), POSITIVE_INFINITY + NEGATIVE_INFINITY, NEGATIVE_INFINITY + POSITIVE_INFINITY, POSITIVE_INFINITY - POSITIVE_INFINITY, NEGATIVE_INFINITY - NEGATIVE_INFINITY, Math.sqrt(-1), Math.log(-1), Math.asin(-2), Math.acos(+2), }; System.out.println(Arrays.toString(allNaNs)); // prints "[NaN, NaN...]" System.out.println(NaN == NaN); // prints "false" System.out.println(Double.isNaN(NaN)); // prints "true" } }
Output
231b@aurora ~/handout $ javac GenerateNaN.java 231b@aurora ~/handout $ java GenerateNaN [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN] false true