\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 -1.0851793033426899 \cdot 10^{+83}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -1.1229326325662633 \cdot 10^{-120}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\
\mathbf{elif}\;b \leq 1.5749587218084831 \cdot 10^{+134}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\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 -1.0851793033426899e+83)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b -1.1229326325662633e-120)
(*
-0.5
(/ (/ (* 4.0 (* c a)) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))) a))
(if (<= b 1.5749587218084831e+134)
(* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.0))))) a))
(* -0.5 (- (* 2.0 (/ b a)) (* 2.0 (/ 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 <= -1.0851793033426899e+83) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= -1.1229326325662633e-120) {
tmp = -0.5 * (((4.0 * (c * a)) / (b - sqrt((b * b) - (4.0 * (c * a))))) / a);
} else if (b <= 1.5749587218084831e+134) {
tmp = -0.5 * ((b + sqrt((b * b) + (a * (c * -4.0)))) / a);
} else {
tmp = -0.5 * ((2.0 * (b / a)) - (2.0 * (c / b)));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.1 |
|---|---|
| Target | 21.0 |
| Herbie | 9.1 |
if b < -1.08517930334268993e83Initial program 58.7
Simplified58.7
Taylor expanded around -inf 2.7
if -1.08517930334268993e83 < b < -1.1229326325662633e-120Initial program 39.5
Simplified39.5
rmApplied flip-+_binary64_175739.5
Simplified15.7
if -1.1229326325662633e-120 < b < 1.5749587218084831e134Initial program 11.7
Simplified11.7
rmApplied sub-neg_binary64_177611.7
Simplified11.7
if 1.5749587218084831e134 < b Initial program 57.1
Simplified57.1
Taylor expanded around inf 3.1
Final simplification9.1
herbie shell --seed 2021015
(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)))