\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.0164007120358223 \cdot 10^{+98}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -1.7338129079736815 \cdot 10^{-293}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 6.972667102848289 \cdot 10^{+99}:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\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.0164007120358223e+98)
(- (/ c b) (/ b a))
(if (<= b -1.7338129079736815e-293)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 6.972667102848289e+99)
(* -2.0 (/ c (+ b (sqrt (- (* b b) (* c (* a 4.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.0164007120358223e+98) {
tmp = (c / b) - (b / a);
} else if (b <= -1.7338129079736815e-293) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
} else if (b <= 6.972667102848289e+99) {
tmp = -2.0 * (c / (b + sqrt((b * b) - (c * (a * 4.0)))));
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.5 |
|---|---|
| Target | 21.0 |
| Herbie | 6.7 |
if b < -1.01640071203582227e98Initial program 46.2
Simplified46.2
Taylor expanded around -inf 3.9
if -1.01640071203582227e98 < b < -1.73381290797368148e-293Initial program 9.6
if -1.73381290797368148e-293 < b < 6.97266710284828931e99Initial program 31.7
Simplified31.7
rmApplied flip--_binary64_173731.7
Simplified16.2
Simplified16.2
rmApplied *-un-lft-identity_binary64_176216.2
Applied times-frac_binary64_176814.0
Applied times-frac_binary64_17688.8
Simplified8.8
Simplified8.8
if 6.97266710284828931e99 < b Initial program 59.4
Simplified59.4
Taylor expanded around inf 2.7
Simplified2.7
Final simplification6.7
herbie shell --seed 2020292
(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)))