double neg = -0.0;
double result = neg + 0.0;
System.out.println(result==neg);
double pos = 0.0;
double neg = -0.0;
System.out.println(pos == neg);
System.out.println(Double.compare(pos, neg));
So, whether the two are considered equal depends on how they are compared. Check the API for Double.equals Same value maybe but internal representation isIf that's addressed at me, I--and the post I was responding to--was talking about real numbers, not Java's representation.
different. (The bit is present or not).
That will be true regardless of whether it's +0.0 or -0.0, since -0.0 == +0.0.double neg = -0.0; double result = neg + 0.0; System.out.println(result==neg);
That will be true regardless of whether it's +0.0 orTry it with Double instead of double.
-0.0, since -0.0 == +0.0.
mathematically there's a difference between -0.0 andEh? 0.0 is a specific value. How does putting a + or - in front of it change that?
+0.0 (though it's rather obscure, having to do mostly
with asymptotic curves approaching 0 from below and
above never touching).
More of a notation issue than anything else :)True, but read my reply #4; +0 and -0 are different in certain circumstances.
public class Test4
{
public static void main(String[] args)
{
double neg = -0.0;
double pos = 0.0;
double result = 1;
result = neg + pos;
if(neg==pos)
System.out.println("neg and pos are the same");
else
System.out.println("neg and pos are not the same");
if(result == pos)
System.out.println("result and pos are the same");
else if(result == neg)
System.out.println("neg and result are the same");
}
}
So adding -0 to +0 gives +0.neg and pos are the same
result and pos are the same