...
Code Block | ||
---|---|---|
| ||
public class NaNComparison { public static void main(String[] args) { double x = 0.0; double result = Double.NaN;Math.cos(1/x); // returns NaN if input is infinity if(result == Double.NaN) // compare with infinity System.out.println("Both are equal"); } } |
...
Code Block | ||
---|---|---|
| ||
public class NaNComparison { public static void main(String[] args) { double x = 0.0; double result = Double.NaN;Math.cos(1/x); // returns NaN if input is infinity if(Double.isNaN(result)) System.out.println("Both are equal"); } } |
...