\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 -1.6236541306877014 \cdot 10^{+56}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\
\mathbf{elif}\;b \leq 7.131198222427231 \cdot 10^{-227}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{elif}\;b \leq 5.525835260688754 \cdot 10^{+121}:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{c}{2 \cdot \left(b - \frac{a \cdot c}{b}\right)}\\
\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 -1.6236541306877014e+56)
(/ (* 2.0 (- (/ (* a c) b) b)) (* 2.0 a))
(if (<= b 7.131198222427231e-227)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))
(if (<= b 5.525835260688754e+121)
(* -2.0 (/ c (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))
(* -2.0 (/ c (* 2.0 (- b (/ (* a 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 <= -1.6236541306877014e+56) {
tmp = (2.0 * (((a * c) / b) - b)) / (2.0 * a);
} else if (b <= 7.131198222427231e-227) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (2.0 * a);
} else if (b <= 5.525835260688754e+121) {
tmp = -2.0 * (c / (b + sqrt((b * b) - (c * (a * 4.0)))));
} else {
tmp = -2.0 * (c / (2.0 * (b - ((a * c) / b))));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.6 |
|---|---|
| Target | 20.5 |
| Herbie | 8.6 |
if b < -1.6236541306877014e56Initial program 38.1
Simplified38.1
Taylor expanded around -inf 11.2
Simplified11.2
if -1.6236541306877014e56 < b < 7.131198222427231e-227Initial program 10.2
Simplified10.2
if 7.131198222427231e-227 < b < 5.52583526068875372e121Initial program 36.8
Simplified36.8
rmApplied flip--_binary64_143036.8
Simplified17.2
Simplified17.2
rmApplied *-un-lft-identity_binary64_145517.2
Applied times-frac_binary64_146114.4
Applied times-frac_binary64_14617.1
Simplified7.1
Simplified7.1
if 5.52583526068875372e121 < b Initial program 61.3
Simplified61.3
rmApplied flip--_binary64_143061.3
Simplified34.3
Simplified34.3
rmApplied *-un-lft-identity_binary64_145534.3
Applied times-frac_binary64_146134.2
Applied times-frac_binary64_146132.6
Simplified32.6
Simplified32.6
Taylor expanded around inf 5.5
Simplified5.5
Final simplification8.6
herbie shell --seed 2020281
(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)))