\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 -2.3044033969831823 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\
\mathbf{elif}\;b \le 8.9305277508569929 \cdot 10^{-82}:\\
\;\;\;\;\frac{1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}{2 \cdot a}\\
\mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\
\;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\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 temp;
if ((b <= -2.3044033969831823e+153)) {
temp = (1.0 * ((c / b) - (b / a)));
} else {
double temp_1;
if ((b <= 8.930527750856993e-82)) {
temp_1 = ((1.0 * (sqrt(((b * b) - ((4.0 * a) * c))) - b)) / (2.0 * a));
} else {
double temp_2;
if ((b <= 4.019930844191633e+109)) {
temp_2 = ((1.0 / (cbrt((-b - sqrt(((b * b) - ((4.0 * a) * c))))) * cbrt((-b - sqrt(((b * b) - ((4.0 * a) * c))))))) / (((2.0 * a) / (4.0 * (a * c))) * cbrt((-b - sqrt(((b * b) - ((4.0 * a) * c)))))));
} else {
temp_2 = (-1.0 * (c / b));
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.1 |
|---|---|
| Target | 20.7 |
| Herbie | 9.3 |
if b < -2.3044033969831823e+153Initial program 63.5
Taylor expanded around -inf 2.0
Simplified2.0
if -2.3044033969831823e+153 < b < 8.930527750856993e-82Initial program 12.5
rmApplied *-un-lft-identity12.5
Applied *-un-lft-identity12.5
Applied distribute-lft-out12.5
Simplified12.5
if 8.930527750856993e-82 < b < 4.019930844191633e+109Initial program 43.0
rmApplied flip-+43.0
Simplified14.9
rmApplied add-cube-cbrt15.6
Applied *-un-lft-identity15.6
Applied times-frac15.6
Applied associate-/l*14.3
Simplified13.8
if 4.019930844191633e+109 < b Initial program 59.9
Taylor expanded around inf 2.4
Final simplification9.3
herbie shell --seed 2020060 +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)))