\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 -5.9369607730911 \cdot 10^{+148}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -2.460485954681045 \cdot 10^{-307}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.4128408816895354 \cdot 10^{+64}:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\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 -5.9369607730911e+148)
(- (/ c b) (/ b a))
(if (<= b -2.460485954681045e-307)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 2.4128408816895354e+64)
(* -2.0 (/ c (+ b (sqrt (- (* b b) (* c (* a 4.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 <= -5.9369607730911e+148) {
tmp = (c / b) - (b / a);
} else if (b <= -2.460485954681045e-307) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
} else if (b <= 2.4128408816895354e+64) {
tmp = -2.0 * (c / (b + sqrt((b * b) - (c * (a * 4.0)))));
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.9 |
|---|---|
| Target | 20.6 |
| Herbie | 6.9 |
if b < -5.93696077309109994e148Initial program 62.6
Simplified62.6
Taylor expanded around -inf 2.5
if -5.93696077309109994e148 < b < -2.46048595468104508e-307Initial program 9.0
if -2.46048595468104508e-307 < b < 2.41284088168953543e64Initial program 29.9
Simplified29.9
rmApplied flip--_binary64_107629.9
Simplified17.2
Simplified17.2
rmApplied *-un-lft-identity_binary64_110117.2
Applied times-frac_binary64_110714.2
Applied times-frac_binary64_11079.1
Simplified9.1
Simplified9.1
if 2.41284088168953543e64 < b Initial program 57.6
Simplified57.6
Taylor expanded around inf 3.7
Simplified3.7
Final simplification6.9
herbie shell --seed 2020346
(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)))