\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 -7.102439644234899 \cdot 10^{-32}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 9.908180707161701 \cdot 10^{-62}:\\
\;\;\;\;\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 -7.102439644234899e-32)
(/ (- (- b) b) (* a 2.0))
(if (<= b 9.908180707161701e-62)
(/ (- (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 <= -7.102439644234899e-32) {
tmp = (-b - b) / (a * 2.0);
} else if (b <= 9.908180707161701e-62) {
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.6 |
|---|---|
| Target | 21.3 |
| Herbie | 10.9 |
if b < -7.1024396442348992e-32Initial program 30.2
Simplified30.2
Taylor expanded around -inf 8.8
Simplified8.8
if -7.1024396442348992e-32 < b < 9.9081807071617013e-62Initial program 15.4
if 9.9081807071617013e-62 < b Initial program 54.2
Simplified54.2
Taylor expanded around inf 8.3
Final simplification10.9
herbie shell --seed 2021044
(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)))