Is it possible to get division by 0 (or infinity) in the following example?
public double calculation(double a, double
You shouldn't ever compare floats or doubles for equality; because, you can't really guarantee that the number you assign to the float or double is exact.
To compare floats for equality sanely, you need to check if the value is "close enough" to the same value:
if ((first >= second - error) || (first <= second + error)