\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 -6.179728259456902 \cdot 10^{+149}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\mathbf{elif}\;b \leq -5.113553016801333 \cdot 10^{-306}:\\
\;\;\;\;\frac{0}{2 \cdot a} - \frac{b - \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}{2 \cdot a}\\
\mathbf{elif}\;b \leq 1.580016373421664 \cdot 10^{+72}:\\
\;\;\;\;\frac{-2 \cdot c}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\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 -6.179728259456902e+149)
(/ (* b -2.0) (* 2.0 a))
(if (<= b -5.113553016801333e-306)
(-
(/ 0.0 (* 2.0 a))
(/ (- b (sqrt (- (* b b) (* (* a 4.0) c)))) (* 2.0 a)))
(if (<= b 1.580016373421664e+72)
(/ (* -2.0 c) (+ b (sqrt (fma a (* c -4.0) (* b b)))))
(- (/ 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.179728259456902e+149) {
tmp = (b * -2.0) / (2.0 * a);
} else if (b <= -5.113553016801333e-306) {
tmp = (0.0 / (2.0 * a)) - ((b - sqrt((b * b) - ((a * 4.0) * c))) / (2.0 * a));
} else if (b <= 1.580016373421664e+72) {
tmp = (-2.0 * c) / (b + sqrt(fma(a, (c * -4.0), (b * b))));
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
| Original | 33.9 |
|---|---|
| Target | 20.6 |
| Herbie | 6.8 |
if b < -6.1797282594569017e149Initial program 61.5
Taylor expanded in b around -inf 2.5
if -6.1797282594569017e149 < b < -5.11355301680133332e-306Initial program 8.9
Applied neg-sub0_binary648.9
Applied associate-+l-_binary648.9
Applied div-sub_binary648.9
if -5.11355301680133332e-306 < b < 1.580016373421664e72Initial program 30.4
Simplified30.5
Applied flip--_binary6430.5
Applied associate-*l/_binary6430.6
Simplified16.6
Taylor expanded in c around 0 9.5
if 1.580016373421664e72 < b Initial program 58.2
Taylor expanded in b around inf 2.9
Simplified2.9
Final simplification6.8
herbie shell --seed 2021357
(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)))