# Jagan Tirumalai

Greenhorn
since Jul 05, 2005
For More
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## 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).

Constant Field Values
18 years ago
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?

18 years ago