\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 -3.77413468628334187 \cdot 10^{-17}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \le 1.2919983862558445 \cdot 10^{30}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-\sqrt[3]{b} \cdot \sqrt[3]{b}, \sqrt[3]{b}, -\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\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 VAR;
if ((b <= -3.774134686283342e-17)) {
VAR = (-1.0 * (c / b));
} else {
double VAR_1;
if ((b <= 1.2919983862558445e+30)) {
VAR_1 = (fma(-(cbrt(b) * cbrt(b)), cbrt(b), -sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a));
} else {
VAR_1 = (1.0 * ((c / b) - (b / a)));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.7 |
|---|---|
| Target | 20.5 |
| Herbie | 11.2 |
if b < -3.774134686283342e-17Initial program 54.4
Taylor expanded around -inf 6.7
if -3.774134686283342e-17 < b < 1.2919983862558445e+30Initial program 16.8
rmApplied add-cube-cbrt17.0
Applied distribute-lft-neg-in17.0
Applied fma-neg17.0
if 1.2919983862558445e+30 < b Initial program 34.2
Taylor expanded around inf 6.6
Simplified6.6
Final simplification11.2
herbie shell --seed 2020100 +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)))