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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "[about zero]..." Watch "[about zero]..." New topic
Author

[about zero]...

chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
public void check()
{
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));
}
answer: -0.0 +0.0 true
if there are positive and negative zero,
why the answer of (Math.min(-0.0,+0.0) == Math.max(0.0,+0.0))
will be true??
thanks for help.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
This has to do with the implementation of Math.min() and Math.max() methods.These methods treat -0.0 as less than +0.0.However, these are NOT numeric comparisions.
When you test -0.0 == +0.0 you are doing a numeric comparision which results in true.
Hope this helps,
Sandeep
SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
tvs sundaram
Ranch Hand

Joined: Jan 28, 2001
Posts: 153

Good Question, Mr. chao-long liao
&
Good Answer, Mr Desai Sandeep
I have learnt something new today; Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: [about zero]...
 
Similar Threads
Min and Max problem
Majji #Q.28
(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
Math.min and Math. max
majji's question