Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

== operator????

 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));

why is this print true?
(min = -0.0) == (max = 0.0)???

another thing, how is the conversion of decimal in binary of negative numbers done?
48 = 11 0000
-48 = ???
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Math.min(-0.0,+0.0) returns -0.0
Math.max(0.0,+0.0) returns 0.0
From JLS 15.21.1 Numerical Equality Operators == and !=

...
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
...

The conversion of negative decimal numbers to binary has been heavily discussed in the following threads:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014657
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=003578
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic