\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 -8.48011838473109798 \cdot 10^{-73}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \le 4.7852092117837367 \cdot 10^{-95}:\\
\;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{a}}{2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \mathsf{fma}\left(\sqrt[3]{\frac{c}{b}} \cdot \sqrt[3]{\frac{c}{b}}, \sqrt[3]{\frac{c}{b}}, -\frac{b}{a}\right)\\
\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 <= -8.480118384731098e-73)) {
temp = (-1.0 * (c / b));
} else {
double temp_1;
if ((b <= 4.7852092117837367e-95)) {
temp_1 = (((fma(b, b, -((b * b) - (4.0 * (a * c)))) / a) / 2.0) / (-b + sqrt(((b * b) - (4.0 * (a * c))))));
} else {
temp_1 = (1.0 * fma((cbrt((c / b)) * cbrt((c / b))), cbrt((c / b)), -(b / a)));
}
temp = temp_1;
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.7 |
|---|---|
| Target | 20.6 |
| Herbie | 13.0 |
if b < -8.480118384731098e-73Initial program 53.4
Taylor expanded around -inf 8.5
if -8.480118384731098e-73 < b < 4.7852092117837367e-95Initial program 17.4
rmApplied div-inv17.5
rmApplied flip--20.5
Applied associate-*l/20.5
Simplified20.4
if 4.7852092117837367e-95 < b Initial program 25.5
Taylor expanded around inf 11.4
Simplified11.4
rmApplied add-cube-cbrt11.4
Applied fma-neg11.4
Final simplification13.0
herbie shell --seed 2020066 +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)))