\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 -8.25042444002418 \cdot 10^{+133}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 2.9229233280338277 \cdot 10^{-125}:\\
\;\;\;\;-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 4.492769536356283 \cdot 10^{+57}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\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 -8.25042444002418e+133)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 2.9229233280338277e-125)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 4.492769536356283e+57)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(* -0.5 (/ (+ b b) a))))))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 <= -8.25042444002418e+133) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 2.9229233280338277e-125) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 4.492769536356283e+57) {
tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (2.0 * a);
} else {
tmp = -0.5 * ((b + b) / a);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.0 |
|---|---|
| Target | 20.6 |
| Herbie | 6.9 |
if b < -8.25042444002418047e133Initial program 61.6
Simplified61.6
Taylor expanded around -inf 1.8
if -8.25042444002418047e133 < b < 2.92292332803382766e-125Initial program 29.2
Simplified29.2
rmApplied flip-+_binary64_209830.1
Simplified16.6
rmApplied *-un-lft-identity_binary64_212416.6
Applied *-un-lft-identity_binary64_212416.6
Applied times-frac_binary64_213016.7
Applied times-frac_binary64_213016.7
Simplified16.7
Simplified10.3
if 2.92292332803382766e-125 < b < 4.49276953635628308e57Initial program 5.2
if 4.49276953635628308e57 < b Initial program 38.7
Simplified38.7
Taylor expanded around inf 5.4
Final simplification6.9
herbie shell --seed 2021007
(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)))