\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \leq -1.155604409696689 \cdot 10^{+145}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.5261316372246074 \cdot 10^{-97}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\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.155604409696689e+145)
(/ (- b) a)
(if (<= b 1.5261316372246074e-97)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(- (/ 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.155604409696689e+145) {
tmp = -b / a;
} else if (b <= 1.5261316372246074e-97) {
tmp = (sqrt((b * b) - ((a * 4.0) * c)) - b) / (a * 2.0);
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.8 |
|---|---|
| Target | 20.5 |
| Herbie | 9.6 |
if b < -1.155604409696689e145Initial program 61.6
Simplified61.6
Taylor expanded around -inf 2.3
Simplified2.3
if -1.155604409696689e145 < b < 1.5261316372246074e-97Initial program 11.3
if 1.5261316372246074e-97 < b Initial program 52.3
Simplified52.3
Taylor expanded around inf 9.6
Simplified9.6
Final simplification9.6
herbie shell --seed 2020357
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))