This week's giveaway is in the Testing forum.We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
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
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# NaN values..

Ranch Hand
Posts: 106
• Number of slices to send:
Optional 'thank-you' note:
Given the code:
Float f1 = new Float(Float.NaN);
Float f2 = new Float(Float.NaN);
System.out.println( ""+ (f1 == f2)+" "+f1.equals(f2)+ " "+(Float.NaN == Float.NaN) );

Ans : false,true,false

Although f1.equals(f2) should return false, it returns true. Javadoc gives two exceptional cases:
. If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN==Float.NaN has the value false.
. If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f==-0.0f has the value true.

Doubt: IS it true for Double.NaN values also???

Sheriff
Posts: 11343
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Swapnil Trivedi:
. If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN==Float.NaN has the value false.
. If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal test has the value false, even though 0.0f==-0.0f has the value true.

Doubt: IS it true for Double.NaN values also???

Well, the API documentation for Double contains the same wording. I wonder how difficult this would be to test?
[ June 25, 2006: Message edited by: marc weber ]

Swapnil Trivedi
Ranch Hand
Posts: 106
• Number of slices to send:
Optional 'thank-you' note:
I just got that in a practice exam and I posted it here....
My apologies

Regards
Swapnil

 So you made a portal in time and started grabbing people. This tiny ad thinks that's rude: Free, earth friendly heat - from the CodeRanch trailboss https://www.kickstarter.com/projects/paulwheaton/free-heat