\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 -6.936942472764157 \cdot 10^{+83}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -1.2572184622052755 \cdot 10^{-278}:\\
\;\;\;\;-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.506449921036379 \cdot 10^{+122}:\\
\;\;\;\;\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 \cdot 2}{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 -6.936942472764157e+83)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b -1.2572184622052755e-278)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 4.506449921036379e+122)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(* -0.5 (/ (* b 2.0) 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 <= -6.936942472764157e+83) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= -1.2572184622052755e-278) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 4.506449921036379e+122) {
tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (2.0 * a);
} else {
tmp = -0.5 * ((b * 2.0) / a);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.2 |
|---|---|
| Target | 20.3 |
| Herbie | 6.9 |
if b < -6.93694247276415666e83Initial program 57.8
Simplified57.8
Taylor expanded around -inf 3.4
if -6.93694247276415666e83 < b < -1.25721846220527553e-278Initial program 32.0
Simplified31.9
rmApplied flip-+_binary64_209832.0
Simplified16.6
rmApplied *-un-lft-identity_binary64_212416.6
Applied *-un-lft-identity_binary64_212416.6
Applied times-frac_binary64_213016.6
Applied times-frac_binary64_213016.6
Simplified16.6
Simplified8.8
if -1.25721846220527553e-278 < b < 4.50644992103637885e122Initial program 9.4
if 4.50644992103637885e122 < b Initial program 52.3
Simplified52.4
rmApplied flip-+_binary64_209863.6
Simplified62.5
Taylor expanded around 0 3.0
Simplified3.0
Final simplification6.9
herbie shell --seed 2020356
(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)))