Double.NaN is not equal to itself, which can have some strange consequences. - Java Language Basics

Java examples for Language Basics:double

Description

Double.NaN is not equal to itself, which can have some strange consequences.

Demo Code

public class Main {
  public static void main(String[] args) {
    double x = Math.sqrt(-50);    // Not a number
    double y = x;
    if (x == y)/*from   ww  w  .j a v  a2  s. c  o  m*/
          System.out.println("x equals y");

  }

}

Related Tutorials