Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: provided more rationale for the NCE/CS

...

Code Block
bgColor#FFcccc
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
bgColor#ccccff
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");
  }
}

...