This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Floating point operations

 
Binu K Idicula
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(Float.MIN_VALUE+1);
System.out.println(Float.MIN_VALUE);
System.out.println(Float.MIN_VALUE-1);
yeilded
1.0
1.4E-45
-1.0
where can I get some short notes on floating point operations?
Your help needed .. ..
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to keep in mind here is that Float.MIN_VALUE is the smallest positive value representable as a float. This is very different from Integer.MIN_VALUE which is a large negative number. I wish the designers of Java hadn't used the same name to mean two very different things.
Floating point numbers have a limited amount of precision. If you add Float.MIN_VALUE (1e-45) to either 1 or -1, you will lose precision because there aren't enough bits available to represent 46 decimal places of precision.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic