Nan is a constant value, indicating that an object is not a quantity. However, this value can only exist in values of double and float floating point variables.
The following is a reprinted Article, which is probably sufficient to illustrate this topic:
When I debugged the program today, I accidentally found Nan in the floating point number of Java, and kept a record.
Java code
- /**
- * Test the Nan in the Java floating point number.
- * @ Author ayis
- *
- * Feb 23,200 9
- */
- Public class testnan {
- Public static
Void main (string ARGs []) {
- // There is a nan value in the double and float types
- Double A = 0, B =
0, C;
- C = A/(A + B );
- System. Out. println (C );
- // In int and long types, there is no nan value. Release the annotation and an exception will be thrown here ---/by zero
- // Int A = 0, B = 0, C;
- // C = A/(A + B );
- // System. Out. println (C );
- // If Nan is compared with any number, false is returned.
- If (0> C) | (0 = C) | (0 <C )){
- System. Out. println ("Nan compared with 0 is not always false .");
- } Else {
- System. Out. println ("Nan compared with 0 is always false! ");
- }
- }
- }
/*** Test the Nan * @ author ayis ** Feb 23,200 9 */public class testnan {public static void main (string ARGs []) in the Java floating point number. {// In the double and float types, there are Nan values of Double A = 0, B = 0, C; C = A/(a + B); system. out. println (c); // In the int and long types, there is no nan value. Release the annotation. An exception will be thrown here ---/by zero // int A = 0, B = 0, c; // C = A/(a + B); // system. out. println (c); // returns falseif (0> C) when comparing nan with any number | (0 = C) | (0 <C) {system. out. println ("Nan compared With 0 is not always false. ");} else {system. Out. println (" Nan compared with 0 is always false! ");}}}