\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.0241087845909653 \cdot 10^{+99}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -1.2708710508270122 \cdot 10^{-228}:\\
\;\;\;\;-0.5 \cdot \frac{c}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{4}}\\
\mathbf{elif}\;b \leq 2.763946614645106 \cdot 10^{+115}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{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 -3.0241087845909653e+99)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b -1.2708710508270122e-228)
(* -0.5 (/ c (/ (- b (sqrt (- (* b b) (* 4.0 (* c a))))) 4.0)))
(if (<= b 2.763946614645106e+115)
(* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.0))))) a))
(* -0.5 (/ (+ b b) 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 <= -3.0241087845909653e+99) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= -1.2708710508270122e-228) {
tmp = -0.5 * (c / ((b - sqrt((b * b) - (4.0 * (c * a)))) / 4.0));
} else if (b <= 2.763946614645106e+115) {
tmp = -0.5 * ((b + sqrt((b * b) + (a * (c * -4.0)))) / a);
} else {
tmp = -0.5 * ((b + b) / a);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.3 |
|---|---|
| Target | 20.9 |
| Herbie | 6.6 |
if b < -3.024108784590965e99Initial program 59.7
Simplified59.7
Taylor expanded around -inf 2.8
if -3.024108784590965e99 < b < -1.27087105082701218e-228Initial program 35.7
Simplified35.7
rmApplied flip-+_binary6435.7
Simplified16.3
rmApplied clear-num_binary6416.4
Simplified7.7
rmApplied associate-/r*_binary647.3
Simplified7.2
if -1.27087105082701218e-228 < b < 2.7639466146451059e115Initial program 9.8
Simplified9.8
rmApplied sub-neg_binary649.8
Simplified9.8
if 2.7639466146451059e115 < b Initial program 51.9
Simplified52.0
Taylor expanded around inf 3.5
Final simplification6.6
herbie shell --seed 2021118
(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)))