This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what this code returns true

 
kavitha satteli
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(0.0 == -0.0)
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thr

i dont know if i got your doubt or not
but will say
since the values +0.0 and -0.0 are identical
or same so it returns true..............
if you have some other doubt do let us know
please be specific with your doubt....?
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In mathematical terms, +0.0 and -0.0 are the same, so that's why Java defines that comparison to return true. As you may know, it is true that +0.0 and -0.0 have different underlying bit representations, but you can't distinguish between them using the == operator.

However, the Double class does distinguish between the two, so this will print false:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic