Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Min and Max problem

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain this answer to me
System.out.println(Math.min(-0.0,+0.0));
System.out.println(Math.max(0.0,+0.0));
System.out.println(Math.min(-0.0,+0.0)==Math.max(0.0,+0.0));
It prints out
-0.0
0.0
true.
Is -0.0 same as 0.0 .
Thanks
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get , its a simple rule.
Yes. Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true. Its a rule of the language.
Read more about such rules in JLS.

Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
cmacpher
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not in Oracle +0 = 0 > -0 This is true in 7.x 8.x 9.x
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cmacpher,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.
PS: Quote from the naming policy:

For your publicly displayed name, use a first name, a space, and a last name. Obviously fictitious names or improperly formatted names may be locked out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic