| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
How can you compare NaN values?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How can you compare NaN values?Floating-point numbers are ordered from -∞, -y (negative finite nonzero values), -0, +0, +y, +∞. The float and double types represent 32- and 64-bit IEEE 754 floating-point numbers. The special number NaN (not-a-number) is unordered and has the following characters:
In particular,
To verify a floating point value is NaN, use the The wrapper classes such as Float and Double have the same behavior when using the above comparison operators.
Comparing two NaN
public class Program {
public static void main(String[] s){
Double a = new Double(Double.NaN);
Double b = new Double(Double.NaN);
if( Double.NaN == Double.NaN )
System.out.println("True");
else
System.out.println("False");
if( a.equals(b) )
System.out.println("True");
else
System.out.println("False");
}
}
The output is False True
ReferencesTricks and traps with floating point and decimal numbers |