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

Math.min() and Math.max()

 
Meg Adal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following code

The output was
0
0
true
-0.0
0.0
true

I saw the API which says that

public static double min(double a,
double b)
this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.

Why there is -ve zero for double but not for integer
Thanks in advance
Megan
[ August 15, 2002: Message edited by: Megan Adal ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The representation of doubles (and floats) is: sign bit, exponent, mantissa. Negative zero differs from positive zero only in the sign bit.
The representation of integers is "two's-complement", which has only one zero.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic