• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.max and Math.min

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic