\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 -3.8933131748243174 \cdot 10^{+118}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 6.117566134779201 \cdot 10^{-229}:\\
\;\;\;\;-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 2.6178552751939085 \cdot 10^{+28}:\\
\;\;\;\;-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 \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 -3.8933131748243174e+118)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 6.117566134779201e-229)
(* -0.5 (* 4.0 (/ c (- b (sqrt (+ (* b b) (* a (* c -4.0))))))))
(if (<= b 2.6178552751939085e+28)
(* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.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 <= -3.8933131748243174e+118) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 6.117566134779201e-229) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) + (a * (c * -4.0))))));
} else if (b <= 2.6178552751939085e+28) {
tmp = -0.5 * ((b + sqrt((b * b) + (a * (c * -4.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.9 |
|---|---|
| Target | 21.7 |
| Herbie | 7.2 |
if b < -3.8933131748243174e118Initial program 60.8
Simplified60.8
Taylor expanded around -inf 2.3
if -3.8933131748243174e118 < b < 6.117566134779201e-229Initial program 31.0
Simplified31.0
rmApplied flip-+_binary6431.1
Simplified16.0
rmApplied *-un-lft-identity_binary6416.0
Applied *-un-lft-identity_binary6416.0
Applied times-frac_binary6416.1
Applied times-frac_binary6416.1
Simplified16.1
Simplified9.4
rmApplied sub-neg_binary649.4
Simplified9.4
if 6.117566134779201e-229 < b < 2.61785527519390851e28Initial program 9.8
Simplified9.7
rmApplied sub-neg_binary649.7
Simplified9.8
if 2.61785527519390851e28 < b Initial program 37.2
Simplified37.2
Taylor expanded around inf 5.9
Simplified5.9
Final simplification7.2
herbie shell --seed 2020224
(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)))