\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 -3.475153330017618 \cdot 10^{+131}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.190818973144896 \cdot 10^{-194}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.928533493233392 \cdot 10^{+129}:\\
\;\;\;\;\frac{c \cdot -2}{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 -3.475153330017618e+131)
(- (/ c b) (/ b a))
(if (<= b 4.190818973144896e-194)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 1.928533493233392e+129)
(/ (* c -2.0) (+ 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 <= -3.475153330017618e+131) {
tmp = (c / b) - (b / a);
} else if (b <= 4.190818973144896e-194) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
} else if (b <= 1.928533493233392e+129) {
tmp = (c * -2.0) / (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.3 |
|---|---|
| Target | 21.1 |
| Herbie | 6.7 |
if b < -3.475153330017618e131Initial program 54.9
Simplified54.9
Taylor expanded around -inf 2.9
if -3.475153330017618e131 < b < 4.1908189731448958e-194Initial program 10.4
Simplified10.4
if 4.1908189731448958e-194 < b < 1.9285334932333919e129Initial program 38.1
Simplified38.1
rmApplied div-inv_binary64_178038.2
Simplified38.2
rmApplied flip--_binary64_175838.2
Applied associate-*l/_binary64_172638.2
Simplified15.4
Taylor expanded around 0 6.8
Simplified6.8
if 1.9285334932333919e129 < b Initial program 61.1
Simplified61.1
Taylor expanded around inf 2.2
Simplified2.2
Final simplification6.7
herbie shell --seed 2020343
(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)))