\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.6561570350872246 \cdot 10^{+101}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 2.1823817432263188 \cdot 10^{-275}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)\\
\mathbf{elif}\;b \leq 5.681019323697606 \cdot 10^{+85}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\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 -3.6561570350872246e+101)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 2.1823817432263188e-275)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 5.681019323697606e+85)
(* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.0))))) 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 <= -3.6561570350872246e+101) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 2.1823817432263188e-275) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 5.681019323697606e+85) {
tmp = -0.5 * ((b + sqrt((b * b) + (a * (c * -4.0)))) / 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 | 21.0 |
| Herbie | 6.8 |
if b < -3.6561570350872246e101Initial program 59.7
Simplified59.7
Taylor expanded around -inf 2.9
if -3.6561570350872246e101 < b < 2.182381743226319e-275Initial program 31.6
Simplified31.6
rmApplied flip-+_binary64_74131.6
Simplified16.8
rmApplied *-un-lft-identity_binary64_76716.8
Applied *-un-lft-identity_binary64_76716.8
Applied times-frac_binary64_77316.8
Applied times-frac_binary64_77316.8
Simplified16.8
Simplified9.3
if 2.182381743226319e-275 < b < 5.6810193236976058e85Initial program 8.8
Simplified8.8
rmApplied sub-neg_binary64_7608.8
Simplified8.8
if 5.6810193236976058e85 < b Initial program 43.3
Simplified43.3
Taylor expanded around inf 3.8
Simplified3.8
Final simplification6.8
herbie shell --seed 2020277
(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)))