\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.91160972146253504 \cdot 10^{93}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\
\mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\
\;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\
\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 temp;
if ((b <= -9.911609721462535e+93)) {
temp = (1.0 * ((c / b) - (b / a)));
} else {
double temp_1;
if ((b <= 3.8681552371770574e-95)) {
temp_1 = (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / a) / 2.0);
} else {
temp_1 = ((-2.0 * (c / b)) / 2.0);
}
temp = temp_1;
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.8 |
|---|---|
| Target | 20.5 |
| Herbie | 9.7 |
if b < -9.911609721462535e+93Initial program 45.2
Taylor expanded around -inf 3.4
Simplified3.4
if -9.911609721462535e+93 < b < 3.8681552371770574e-95Initial program 12.5
rmApplied div-inv12.6
rmApplied *-commutative12.6
Applied associate-/r*12.6
Applied associate-*r/12.6
Simplified12.5
if 3.8681552371770574e-95 < b Initial program 52.5
rmApplied div-inv52.5
rmApplied *-commutative52.5
Applied associate-/r*52.5
Applied associate-*r/52.5
Simplified52.5
Taylor expanded around inf 9.2
Final simplification9.7
herbie shell --seed 2020066 +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)))