hashmap - "double, Double, HashSet" in Java -
please see code below.
"double"(upper d) used in hashset, , "double" used x1, x2 , x3. after x1 added hashset, x2 cannot added, x3 can! why??????
thanks in advance :)
hashset<double> hs = new hashset<double>(); double x1, x2, x3; x1 = (double)0/1; system.out.println(hs.add(x1)); //true x2 = (double)0/2; system.out.println(hs.add(x2)); //false x3 = (double)0/-1; system.out.println(hs.add(x3)); //true
and if add "0.0 +" x1, x2 , x3, result follows.
x1 = 0.0 + (double)0/1; system.out.println(hs.add(x1)); //true x2 = 0.0 + (double)0/2; system.out.println(hs.add(x2)); //false x3 = 0.0 + (double)0/-1; system.out.println(hs.add(x3)); //false
try understand difference:
hashset<double> hs = new hashset<double>(); double x1, x2, x3; x1 = (double)0/1; system.out.println(x1 + " "+ hs.add(x1)); //true x2 = (double)0/2; system.out.println(x2 + " " + hs.add(x2)); //false x3 = (double)0/-1; system.out.println(x3 + " " + hs.add(x3)); //true
basically doubles signed , 0/-1 evaluated -0.0 instead of 0.0 x1 or x2.
Comments
Post a Comment