I know double should not be compared with operator operator
This is only true if you do not know how many representation or rounding errors you have. A classic example of what you don't need to do is
0.1 + 0.2 == 0.3 // false :(
However, if you use rounding, for example
if (round4(0.1 + 0.2) == 0.3) // true
from Chronicle of the core Mathematics
public static double round4(double d) { final double factor = 1e4; return d > WHOLE_NUMBER / factor || d < -WHOLE_NUMBER / factor ? d : (long) (d < 0 ? d * factor - 0.5 : d * factor + 0.5) / factor; }
If a is not changed, does * b == 0 always matter?
This is for finite numbers. For infinity and NaN you get NaN , and that doesn't mean anything.
source share