# java – Interesting issue with doubles

I am solving a Codeforces problem, and i ran into an interesting situation with doubles. When i `add(d) to a HashSet` the output is different from the output generated when i `add(0.0)` , although the value of `d` must be `0.0` since condition `d == 0.0` must be true at the add operation. Why?

```HashSet<Double> equations;

...

double d = (double)(y-y0)/(x-x0);
if(y == y0 && d == 0.0) {
}
```

Code:

```    int n;
int c=0;
int x0,y0;
HashSet<Double> equations;

equations = new HashSet<Double>();

for(int i=0;i<n;i++){
if (x == x0) {
}else {
double d = (double)(y-y0)/(x-x0);
if(y == y0 && d == 0.0) {
}
else
}
}
System.out.println(equations.size());
```

-0.0 == 0.0, but Double.valueOf(-0.0) does not equal Double.valueOf(0.0).

A small test for this:

```public static void main(String[] args) throws Exception {
double pos = 0.0;
System.out.println("" + (pos == 0.0)); // true
double neg = -0.0;
System.out.println("" + (neg == 0.0)); // true
System.out.println("" + (neg == pos)); // true
HashSet<Double> set = new HashSet<Double>();