Is it possible to get division by 0 (or infinity) in the following example?
public double calculation(double a, double b)
{
if (a == b)
{
return 0;
}
else
{
return 2 / (a - b);
}
}
In normal cases it will not, of course. But what if a
and b
are very close, can (a-b)
result in being 0
due to precision of the calculation?
Note that this question is for Java, but I think it will apply to most programming languages.