\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 -3.765674528228214 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.206369630189784 \cdot 10^{-304}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2}}{a}\\
\mathbf{elif}\;b \leq 5.69311637248718 \cdot 10^{+122}:\\
\;\;\;\;\frac{c \cdot -2}{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 -3.765674528228214e+85)
(- (/ c b) (/ b a))
(if (<= b 5.206369630189784e-304)
(/ (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) 2.0) a)
(if (<= b 5.69311637248718e+122)
(/ (* c -2.0) (+ 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 <= -3.765674528228214e+85) {
tmp = (c / b) - (b / a);
} else if (b <= 5.206369630189784e-304) {
tmp = ((sqrt((b * b) - (c * (a * 4.0))) - b) / 2.0) / a;
} else if (b <= 5.69311637248718e+122) {
tmp = (c * -2.0) / (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 | 29.8 |
|---|---|
| Target | 18.2 |
| Herbie | 5.8 |
if b < -3.765674528228214e85Initial program 27.0
Taylor expanded in b around -inf 2.7
if -3.765674528228214e85 < b < 5.2063696301897841e-304Initial program 8.2
Applied associate-/r*_binary648.2
if 5.2063696301897841e-304 < b < 5.69311637248718012e122Initial program 32.7
Simplified32.7
Applied flip--_binary6433.0
Applied associate-*l/_binary6433.0
Simplified14.8
Taylor expanded in a around 0 8.5
if 5.69311637248718012e122 < b Initial program 59.7
Taylor expanded in b around inf 2.1
Simplified2.1
Final simplification5.8
herbie shell --seed 2022068
(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)))