wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.max and Math.min Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.max and Math.min" Watch "Math.max and Math.min" New topic
Author

Math.max and Math.min

Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Does anyone know what or how the below line in the below code
works? Math.max(-0.0, +0,0) == Math.min(-0.0, +0,0)

<Code>
public class Q17 {
public void check() {
double f1 = Math.min(-0.0, +0.0);
System.out.println("min" + Math.min(-0.0, +0.0));
System.out.println("max" +
(Math.max(-0.0, +0.0) == Math.min(-0.0, +0.0)));
System.out.println("compare" + Math.max(-0.0, +0.0) );
}
public static void main(String args []) {
new Q17().check();
}
}
<\Code>
Thank you in advance
adrian carlos
Greenhorn

Joined: May 25, 2001
Posts: 1
Hi Charlie,
First look for your code with some changes:

The answer is:

Actually, no matter for number signal. As you can see, the jdk API say:

Returns the greater of two float values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. ...

Hope it helps,
Adrian
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
Originally posted by Charlie Swanson:
[B]Does anyone know what or how the below line in the below code
works? Math.max(-0.0, +0,0) == Math.min(-0.0, +0,0)
Math.max(-0.0, +0.0) = +0.0
Math.min(-0.0, +0.0) = -0.0
But -0.0 = +0.0 if u want to compare them
hope this clears it


sona<br />SCJP
Samith Nambiar
Ranch Hand

Joined: Mar 14, 2001
Posts: 147
hi
-------------------------------------------------------
"Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example."
-------------------------------------------------------
this is a rule of the language and the above line is from the JLS
hope that helps
Samith.P.Nambiar
-----------------------------
harder u try luckier u get
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Thank you all.
I like the phrase "the harder you try the luckier you get".
It seems like lately the harder I study the more confused I get.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.max and Math.min
 
Similar Threads
Majji #Q.28
Math.min and Math.max - exam question
q from Sahir's mock
[about zero]...
Majji question-Comparision results