Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about max_values..." Watch "Question about max_values..." New topic

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

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

The output is:
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.

[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.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: Question about max_values...
It's not a secret anymore!