\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 -7.1093208455340995 \cdot 10^{+90}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -2.038598643446564 \cdot 10^{-267}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.341209881992474 \cdot 10^{+131}:\\
\;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \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 -7.1093208455340995e+90)
(- (/ c b) (/ b a))
(if (<= b -2.038598643446564e-267)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 1.341209881992474e+131)
(* 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 <= -7.1093208455340995e+90) {
tmp = (c / b) - (b / a);
} else if (b <= -2.038598643446564e-267) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
} else if (b <= 1.341209881992474e+131) {
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 | 33.8 |
|---|---|
| Target | 20.9 |
| Herbie | 6.4 |
if b < -7.10932084553409946e90Initial program 45.1
Taylor expanded around -inf 3.7
if -7.10932084553409946e90 < b < -2.03859864344656402e-267Initial program 8.0
if -2.03859864344656402e-267 < b < 1.34120988199247398e131Initial program 32.6
rmApplied flip-+_binary64_177332.6
Simplified16.2
rmApplied *-un-lft-identity_binary64_179916.2
Applied times-frac_binary64_180514.2
Simplified14.2
rmApplied clear-num_binary64_179814.4
Simplified9.3
rmApplied *-un-lft-identity_binary64_17999.3
Applied *-un-lft-identity_binary64_17999.3
Applied times-frac_binary64_18059.3
Applied *-un-lft-identity_binary64_17999.3
Applied times-frac_binary64_18059.3
Applied add-sqr-sqrt_binary64_18219.3
Applied times-frac_binary64_18059.3
Simplified9.3
Simplified8.9
if 1.34120988199247398e131 < b Initial program 61.3
Taylor expanded around inf 1.9
Simplified1.9
Final simplification6.4
herbie shell --seed 2020289
(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)))