\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 -2.1163049469441965 \cdot 10^{+61}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.9526479573216073 \cdot 10^{-45}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - 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 -2.1163049469441965e+61)
(- (/ c b) (/ b a))
(if (<= b 1.9526479573216073e-45)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) 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 <= -2.1163049469441965e+61) {
tmp = (c / b) - (b / a);
} else if (b <= 1.9526479573216073e-45) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.8 |
|---|---|
| Target | 21.5 |
| Herbie | 11.1 |
if b < -2.1163049469441965e61Initial program 40.4
Simplified40.4
Taylor expanded around -inf 5.4
if -2.1163049469441965e61 < b < 1.9526479573216073e-45Initial program 16.2
Simplified16.2
if 1.9526479573216073e-45 < b Initial program 54.3
Simplified54.3
Taylor expanded around inf 7.7
Final simplification11.1
herbie shell --seed 2021046
(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)))