\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 -9.661125962095032 \cdot 10^{+146}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 6.340718814578958 \cdot 10^{-296}:\\
\;\;\;\;-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 3.032635602239435 \cdot 10^{+20}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\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 -9.661125962095032e+146)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 6.340718814578958e-296)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 3.032635602239435e+20)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) 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 <= -9.661125962095032e+146) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 6.340718814578958e-296) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 3.032635602239435e+20) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / 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 | 33.7 |
|---|---|
| Target | 20.4 |
| Herbie | 6.9 |
if b < -9.6611259620950323e146Initial program 63.2
Simplified63.2
Taylor expanded around -inf 1.5
if -9.6611259620950323e146 < b < 6.3407188145789577e-296Initial program 33.2
Simplified33.2
rmApplied flip-+_binary64_73433.3
Simplified15.3
rmApplied *-un-lft-identity_binary64_76015.3
Applied *-un-lft-identity_binary64_76015.3
Applied times-frac_binary64_76615.3
Applied times-frac_binary64_76615.3
Simplified15.3
Simplified7.8
if 6.3407188145789577e-296 < b < 303263560223943492000Initial program 10.2
Simplified10.2
if 303263560223943492000 < b Initial program 33.7
Simplified33.7
Taylor expanded around inf 6.4
Simplified6.4
Final simplification6.9
herbie shell --seed 2020342
(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)))