\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \leq -3.0240412131884295 \cdot 10^{+52}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 2.5099917767557246 \cdot 10^{-266}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)\\
\mathbf{elif}\;b \leq 5.264281589494235 \cdot 10^{+76}:\\
\;\;\;\;-0.5 \cdot \left(\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \frac{1}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)\right)\\
\end{array}(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -3.0240412131884295e+52)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 2.5099917767557246e-266)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 5.264281589494235e+76)
(* -0.5 (* (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (/ 1.0 a)))
(* -0.5 (* 2.0 (- (/ b a) (/ c b))))))))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 tmp;
if (b <= -3.0240412131884295e+52) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 2.5099917767557246e-266) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 5.264281589494235e+76) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) * (1.0 / a));
} else {
tmp = -0.5 * (2.0 * ((b / a) - (c / b)));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.2 |
|---|---|
| Target | 20.9 |
| Herbie | 7.1 |
if b < -3.02404121318842946e52Initial program 57.9
Simplified57.9
Taylor expanded around -inf 3.9
if -3.02404121318842946e52 < b < 2.50999177675572462e-266Initial program 28.3
Simplified28.3
rmApplied flip-+_binary6428.4
Simplified16.7
rmApplied *-un-lft-identity_binary6416.7
Applied *-un-lft-identity_binary6416.7
Applied times-frac_binary6416.7
Applied times-frac_binary6416.7
Simplified16.7
Simplified9.7
if 2.50999177675572462e-266 < b < 5.2642815894942351e76Initial program 9.1
Simplified9.1
rmApplied div-inv_binary649.2
if 5.2642815894942351e76 < b Initial program 42.5
Simplified42.5
Taylor expanded around inf 4.8
Simplified4.8
Final simplification7.1
herbie shell --seed 2020232
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))