Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about max_values...

 
Isabel Wanderley
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone can explain me why the answer is equal unequal equal equal equal ?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic