I know that because of binary double representation, comparison for equality of two double
s is not quite safe. But I need to perform some computation like this:
double a;
//initializing
if(a != 0){ // <----------- HERE
double b = 2 / a;
//do other computation
}
throw new RuntimeException();
So, comparison of double
s is not safe, but I definitely do not want to to devide by 0. What to do in this case?
I'd use BigDecimal
but its performance is not quite acceptable.