\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 -6.386638269559252 \cdot 10^{+115}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8.126739115825835 \cdot 10^{-101}:\\
\;\;\;\;\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 -6.386638269559252e+115)
(/ (- b) a)
(if (<= b 8.126739115825835e-101)
(/ (- (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 <= -6.386638269559252e+115) {
tmp = -b / a;
} else if (b <= 8.126739115825835e-101) {
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 | 34.7 |
|---|---|
| Target | 21.4 |
| Herbie | 9.9 |
if b < -6.38663826955925e115Initial program 50.8
Taylor expanded in b around -inf 3.7
Simplified3.7
if -6.38663826955925e115 < b < 8.1267391158258352e-101Initial program 12.1
if 8.1267391158258352e-101 < b Initial program 52.2
Taylor expanded in b around inf 10.0
Simplified10.0
Final simplification9.9
herbie shell --seed 2022024
(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)))