\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 -7.074176182163289 \cdot 10^{+117}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 8.619636124755816 \cdot 10^{-304}:\\
\;\;\;\;-0.5 \cdot \left(-4 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\right)\\
\mathbf{elif}\;b \leq 5.342562827435607 \cdot 10^{+94}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(4 \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 -7.074176182163289e+117)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 8.619636124755816e-304)
(* -0.5 (* -4.0 (/ c (- (sqrt (- (* b b) (* 4.0 (* c a)))) b))))
(if (<= b 5.342562827435607e+94)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* 4.0 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 <= -7.074176182163289e+117) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 8.619636124755816e-304) {
tmp = -0.5 * (-4.0 * (c / (sqrt((b * b) - (4.0 * (c * a))) - b)));
} else if (b <= 5.342562827435607e+94) {
tmp = -0.5 * ((b + sqrt((b * b) - (c * (4.0 * 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 | 34.1 |
|---|---|
| Target | 20.5 |
| Herbie | 6.3 |
if b < -7.07417618216328877e117Initial program 61.0
Simplified61.0
Taylor expanded around -inf 2.3
if -7.07417618216328877e117 < b < 8.6196361247558162e-304Initial program 33.4
Simplified33.4
rmApplied flip-+_binary6433.4
Simplified16.1
rmApplied *-un-lft-identity_binary6416.1
Applied *-un-lft-identity_binary6416.1
Applied times-frac_binary6416.1
Applied times-frac_binary6416.1
Simplified16.1
Simplified7.6
rmApplied frac-2neg_binary647.6
Simplified7.6
if 8.6196361247558162e-304 < b < 5.34256282743560728e94Initial program 8.9
Simplified8.9
rmApplied associate-*r*_binary648.9
if 5.34256282743560728e94 < b Initial program 45.4
Simplified45.4
Taylor expanded around inf 4.2
Simplified4.2
Final simplification6.3
herbie shell --seed 2021113
(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)))