\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 -1.6000356618606551 \cdot 10^{+106}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.0643624800958176 \cdot 10^{-79}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\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 -1.6000356618606551e+106)
(- (/ c b) (/ b a))
(if (<= b 5.0643624800958176e-79)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) 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 <= -1.6000356618606551e+106) {
tmp = (c / b) - (b / a);
} else if (b <= 5.0643624800958176e-79) {
tmp = (sqrt((b * b) - (4.0 * (c * a))) - 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.0 |
|---|---|
| Target | 20.9 |
| Herbie | 9.8 |
if b < -1.60003566186065514e106Initial program 48.7
Simplified48.7
Taylor expanded around -inf 3.1
if -1.60003566186065514e106 < b < 5.0643624800958176e-79Initial program 12.4
Simplified12.4
if 5.0643624800958176e-79 < b Initial program 53.3
Simplified53.3
Taylor expanded around inf 9.2
Simplified9.2
Final simplification9.8
herbie shell --seed 2020274
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected #f
: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)))