aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about max_values... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about max_values..." Watch "Question about max_values..." New topic
Author

Question about max_values...

Isabel Wanderley
Ranch Hand

Joined: Aug 24, 2002
Posts: 42
Anyone can explain me why the answer is equal unequal equal equal equal ?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Try this out:

The output is:
2.147483647E9
2.14748365E9
and thus the value does not compare equal... This has to do with the precision of the value you can fit into the mantissa of float and doubles.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Isabel, this question has appeared on other forums/threads before. It is generally considered to be a bad question, because of the f == d comparison. Any program comparing floating point numbers for equality is suspect.
Move 'em on, forget it, but remember the reason why you forgot it.
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
 
subject: Question about max_values...