\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \le -9.61279552926933292 \cdot 10^{93}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\
\mathbf{elif}\;b \le 1.76145822117380694 \cdot 10^{-90}:\\
\;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2 \cdot a}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}double code(double a, double b, double c) {
return ((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a));
}
double code(double a, double b, double c) {
double VAR;
if ((b <= -9.612795529269333e+93)) {
VAR = (1.0 * ((c / b) - (b / a)));
} else {
double VAR_1;
if ((b <= 1.761458221173807e-90)) {
VAR_1 = (sqrt((-b + sqrt(((b * b) - ((4.0 * a) * c))))) / ((2.0 * a) / sqrt((-b + sqrt(((b * b) - ((4.0 * a) * c)))))));
} else {
VAR_1 = (-1.0 * (c / b));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.9 |
|---|---|
| Target | 20.5 |
| Herbie | 10.6 |
if b < -9.612795529269333e+93Initial program 45.1
Taylor expanded around -inf 4.1
Simplified4.1
if -9.612795529269333e+93 < b < 1.761458221173807e-90Initial program 13.2
rmApplied add-sqr-sqrt13.5
Applied associate-/l*13.6
if 1.761458221173807e-90 < b Initial program 52.1
Taylor expanded around inf 9.9
Final simplification10.6
herbie shell --seed 2020079 +o rules:numerics
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))