File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "[about zero]..." Watch "[about zero]..." New topic

[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) == 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
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,
SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
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
I agree. Here's the link:
subject: [about zero]...
It's not a secret anymore!