\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.9002502210936553 \cdot 10^{+140}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 4.860998560804722 \cdot 10^{-178}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\right)\\
\mathbf{elif}\;b \leq 6.414833710235507 \cdot 10^{+29}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot 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 -1.9002502210936553e+140)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 4.860998560804722e-178)
(* -0.5 (* 4.0 (/ c (- b (sqrt (+ (* b b) (* a (* c -4.0))))))))
(if (<= b 6.414833710235507e+29)
(* -0.5 (/ 1.0 (/ a (+ b (sqrt (- (* b b) (* 4.0 (* c 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 <= -1.9002502210936553e+140) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 4.860998560804722e-178) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) + (a * (c * -4.0))))));
} else if (b <= 6.414833710235507e+29) {
tmp = -0.5 * (1.0 / (a / (b + sqrt((b * b) - (4.0 * (c * 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.3 |
|---|---|
| Target | 21.1 |
| Herbie | 6.8 |
if b < -1.9002502210936553e140Initial program 62.6
Simplified62.6
Taylor expanded around -inf 2.1
if -1.9002502210936553e140 < b < 4.86099856080472191e-178Initial program 30.3
Simplified30.2
rmApplied flip-+_binary64_108530.4
Simplified15.6
rmApplied *-un-lft-identity_binary64_111115.6
Applied *-un-lft-identity_binary64_111115.6
Applied times-frac_binary64_111715.6
Applied times-frac_binary64_111715.6
Simplified15.6
Simplified9.3
rmApplied sub-neg_binary64_11049.3
Simplified9.3
if 4.86099856080472191e-178 < b < 6.41483371023550709e29Initial program 6.8
Simplified6.8
rmApplied clear-num_binary64_11107.0
if 6.41483371023550709e29 < b Initial program 36.4
Simplified36.4
Taylor expanded around inf 6.1
Simplified6.1
Final simplification6.8
herbie shell --seed 2020289
(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)))