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

Math.min and Math.max - exam question

 
Sharda Vajjhala
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:
public class check{
public static void main(String args[]){
System.out.println(Math.min(-0.0,+0.0));
System.out.println(Math.max(-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));
}
}
This prints:
-0.0
0.0
0.0
true
How does the last stmt return "true" if -0.0 and 0.0 are considered to be different values by Math.min and Math.max?
 
Sharda Vajjhala
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realized as soon as I posted this message that the last stmt is actually an expression and except for the Math.min and Math.max everything else considers -0.0 and +0.0 to be equal. Hence the output of "true"
Sharda
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic