Java floating point mathematics rules

there is a way to avoid an issue by moving calculations to a separate method like this:

    public double safeDivide(double numerator, double denominator, double tolerance) {
        return (Math.abs(denominator) < tolerance) ? 0 : (numerator / denominator);
    }

and invoking this method where rules are triggered. But it’s not a compliant solution…