This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

floating point division

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why is the output infinity
and not -infinity
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get -Infinity you have to use -0.0 as the denominator.

My interpretation of your example is as follows:
-0 is done with integer arithmetic, so -0 -> -(0) -> 0 and that gets converted to 0.0 before the division is done. Therefore (+)Infinity is the result.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic