Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Programmer Certification (OCPJP)
Majji question - NaN
shetal bansal
Ranch Hand
Posts: 63
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What will the following code print:
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 answer is
False
True.
I think that as NaN is not equal to anything including itself how is it that "a.equals(b)" returns true??!!
Because if we do,
double d = Double.NaN; double e = Double.NaN; if(d==e) System.out.println("True"); else System.out.println("False");
This code will print False as NaN is not equal to anything including itself.
Then how do explain the behaviour in the previous code?
Jim Yingst
Wanderer
Posts: 18671
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If all else fails,
check the API
. Under equals() it says: "If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false."
"I'm not back." - Bill Harding,
Twister
shetal bansal
Ranch Hand
Posts: 63
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanxs Jim!!
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Double.NaN ???
NaN
about == equals
Double.NaN (Majji Q)
Q'tion from Majji's paper
More...