Jagan Tirumalai

Greenhorn
+ Follow
since Jul 05, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jagan Tirumalai

This might be of help from Java Docs 1.4 about NaN under Class Double

NaN
public static final double NaN

A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L).

See Also:
Constant Field Values
Hi,

I think == method can be used in Primitive datatypes and not objects.

The moment it becomes Double and not double it becomes an object and plus
NaN is a static value. Since you initialized to both the objects to a constant value it evaluates to true. Replace this with Double.NaN with 1.0
it will evaluate to the same result.



Originally posted by Marcos Vilela:
1: Double a = new Double(Double.NaN);
2: Double b = new Double(Double.NaN);
3:
4: if( Double.NaN == Double.NaN )
5: System.out.println("True");
6: else
7: System.out.println("False");
8:
9: if( a.equals(b) )
10: System.out.println("True");
11: else
12: System.out.println("False");


ok the first expression is false. But why the second one is true if the equals() compare the Double Value?