\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 -1.4220016328491612 \cdot 10^{+151}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 5.126982040291221 \cdot 10^{-283}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)\\
\mathbf{elif}\;b \leq 2.1353619288367854 \cdot 10^{+148}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\
\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.4220016328491612e+151)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 5.126982040291221e-283)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
(if (<= b 2.1353619288367854e+148)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(* -0.5 (/ (* b 2.0) a))))))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.4220016328491612e+151) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 5.126982040291221e-283) {
tmp = -0.5 * (4.0 * (c / (b - sqrt((b * b) - (4.0 * (c * a))))));
} else if (b <= 2.1353619288367854e+148) {
tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (2.0 * a);
} else {
tmp = -0.5 * ((b * 2.0) / a);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.5 |
|---|---|
| Target | 20.4 |
| Herbie | 6.5 |
if b < -1.42200163284916121e151Initial program 63.7
Simplified63.7
Taylor expanded around -inf 1.4
if -1.42200163284916121e151 < b < 5.12698204029122054e-283Initial program 33.9
Simplified33.9
rmApplied flip-+_binary64_73433.9
Simplified15.7
rmApplied *-un-lft-identity_binary64_76015.7
Applied *-un-lft-identity_binary64_76015.7
Applied times-frac_binary64_76615.7
Applied times-frac_binary64_76615.7
Simplified15.7
Simplified8.5
if 5.12698204029122054e-283 < b < 2.13536192883678537e148Initial program 7.9
if 2.13536192883678537e148 < b Initial program 61.3
Simplified61.3
rmApplied flip-+_binary64_73464.0
Simplified62.8
Taylor expanded around 0 3.2
Simplified3.2
Final simplification6.5
herbie shell --seed 2020346
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))