Two NaN values are defined in the java.lang package (Float.NaN and Double.NaN) : float « Java Source And Data Type « SCJP






public class MainClass {
  public static void main(String[] argv) {
    System.out.println(Float.NaN);
    System.out.println(Double.NaN);

    float y = 0.8F;
    float x = (float) Math.sqrt(y); // where y may be negative
    if (x == Float.NaN) {
      x = 0.0F; // WRONG, always false
    }
    if (Float.isNaN(x)) {
      x = 0.0F;
      // the right way to detect NaN
    }
  }
}








1.11.float
1.11.1.The two floating-point types are float and double
1.11.2.A floating-point literal with a decimal point
1.11.3.A floating-point literal with letter E or e (scientific notation)
1.11.4.A floating-point literal with suffix F or f, indicating a float literal
1.11.5.Special floating-point values.
1.11.6.Two NaN values are defined in the java.lang package (Float.NaN and Double.NaN)
1.11.7.NaN values are non-ordinal for comparisons.
1.11.8.Use Float.isNaN(float) or Double.isNaN(double) to check NaN value