\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 -5.110132017758097 \cdot 10^{+93}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 1.1519003584921026 \cdot 10^{-201}:\\
\;\;\;\;-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 1.2510227225299573 \cdot 10^{+109}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\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 -5.110132017758097e+93)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 1.1519003584921026e-201)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 1.2510227225299573e+109)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.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 <= -5.110132017758097e+93) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 1.1519003584921026e-201) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 1.2510227225299573e+109) {
tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (2.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.0 |
|---|---|
| Target | 20.8 |
| Herbie | 6.7 |
if b < -5.1101320177580966e93Initial program 59.3
Simplified59.3
Taylor expanded around -inf 2.9
if -5.1101320177580966e93 < b < 1.1519003584921026e-201Initial program 29.2
Simplified29.2
rmApplied flip-+_binary64_175729.3
Simplified16.5
rmApplied *-un-lft-identity_binary64_178316.5
Applied *-un-lft-identity_binary64_178316.5
Applied times-frac_binary64_178916.5
Applied times-frac_binary64_178916.5
Simplified16.5
Simplified10.1
if 1.1519003584921026e-201 < b < 1.2510227225299573e109Initial program 7.4
if 1.2510227225299573e109 < b Initial program 49.6
Simplified49.6
Taylor expanded around inf 3.0
Simplified3.0
Final simplification6.7
herbie shell --seed 2021027
(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)))