\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.05414749257894333 \cdot 10^{157}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \le 4.3202301259877458 \cdot 10^{-275}:\\
\;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\
\mathbf{elif}\;b \le 1.44430318372460742:\\
\;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{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 <= -4.0541474925789433e+157)) {
VAR = (-1.0 * (c / b));
} else {
double VAR_1;
if ((b <= 4.320230125987746e-275)) {
VAR_1 = ((2.0 * c) / (sqrt(((b * b) - (4.0 * (a * c)))) - b));
} else {
double VAR_2;
if ((b <= 1.4443031837246074)) {
VAR_2 = ((-b - sqrt(((b * b) - (4.0 * (a * c))))) * (1.0 / (2.0 * a)));
} else {
VAR_2 = (1.0 * ((c / b) - (b / a)));
}
VAR_1 = VAR_2;
}
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 | 7.2 |
if b < -4.0541474925789433e+157Initial program 64.0
Taylor expanded around -inf 1.6
if -4.0541474925789433e+157 < b < 4.320230125987746e-275Initial program 32.7
rmApplied div-inv32.8
rmApplied flip--32.8
Simplified15.4
Simplified15.4
rmApplied associate-*l/13.8
Simplified13.8
Taylor expanded around 0 8.4
if 4.320230125987746e-275 < b < 1.4443031837246074Initial program 9.4
rmApplied div-inv9.6
if 1.4443031837246074 < b Initial program 32.2
Taylor expanded around inf 7.6
Simplified7.6
Final simplification7.2
herbie shell --seed 2020103
(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)))