Sharda Vajjhala

Ranch Hand

Posts: 57

posted 15 years ago

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?

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?