\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.941647724720173 \cdot 10^{+151}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{elif}\;b \leq 3.1356574979833072 \cdot 10^{-83}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\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.941647724720173e+151)
(/ (* b -2.0) (* a 2.0))
(if (<= b 3.1356574979833072e-83)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) 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.941647724720173e+151) {
tmp = (b * -2.0) / (a * 2.0);
} else if (b <= 3.1356574979833072e-83) {
tmp = (sqrt((b * b) - (4.0 * (a * c))) - b) / (a * 2.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.7 |
| Herbie | 9.8 |
if b < -1.94164772472017305e151Initial program 62.7
Simplified62.7
Taylor expanded around -inf 2.4
Simplified2.4
if -1.94164772472017305e151 < b < 3.13565749798330719e-83Initial program 12.0
if 3.13565749798330719e-83 < b Initial program 52.5
Simplified52.5
Taylor expanded around inf 9.2
Simplified9.2
Final simplification9.8
herbie shell --seed 2021113
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))