\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \le -4.93452195172866347 \cdot 10^{-12}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\
\mathbf{elif}\;b \le 2.8292124432832862 \cdot 10^{65}:\\
\;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\
\mathbf{else}:\\
\;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\
\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 <= -4.9345219517286635e-12)) {
temp = pow((-1.0 * (c / b)), 1.0);
} else {
double temp_1;
if ((b <= 2.829212443283286e+65)) {
temp_1 = pow(((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)), 1.0);
} else {
temp_1 = pow((1.0 * ((c / b) - (b / a))), 1.0);
}
temp = temp_1;
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.9 |
|---|---|
| Target | 21.0 |
| Herbie | 10.3 |
if b < -4.9345219517286635e-12Initial program 55.4
rmApplied div-inv55.4
rmApplied pow155.4
Applied pow155.4
Applied pow-prod-down55.4
Simplified55.4
Taylor expanded around -inf 6.2
if -4.9345219517286635e-12 < b < 2.829212443283286e+65Initial program 15.7
rmApplied div-inv15.7
rmApplied pow115.7
Applied pow115.7
Applied pow-prod-down15.7
Simplified15.7
if 2.829212443283286e+65 < b Initial program 40.5
rmApplied div-inv40.6
rmApplied pow140.6
Applied pow140.6
Applied pow-prod-down40.6
Simplified40.5
Taylor expanded around inf 4.5
Simplified4.5
Final simplification10.3
herbie shell --seed 2020053 +o rules:numerics
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))