\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 -4.1675890391810646 \cdot 10^{+147}:\\
\;\;\;\;\frac{-b}{a \cdot 2}\\
\mathbf{elif}\;b \leq -1.346684968652724 \cdot 10^{-176}:\\
\;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.857075353436113 \cdot 10^{+153}:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \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 -4.1675890391810646e+147)
(/ (- b) (* a 2.0))
(if (<= b -1.346684968652724e-176)
(/
(*
(sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b))
(sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b)))
(* a 2.0))
(if (<= b 2.857075353436113e+153)
(* -2.0 (/ c (+ b (sqrt (- (* b b) (* (* a 4.0) c))))))
(* -2.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 <= -4.1675890391810646e+147) {
tmp = -b / (a * 2.0);
} else if (b <= -1.346684968652724e-176) {
tmp = (sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b) * sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b)) / (a * 2.0);
} else if (b <= 2.857075353436113e+153) {
tmp = -2.0 * (c / (b + sqrt((b * b) - ((a * 4.0) * c))));
} else {
tmp = -2.0 * (c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.3 |
|---|---|
| Target | 20.6 |
| Herbie | 17.5 |
if b < -4.1675890391810646e147Initial program 61.7
Simplified61.7
Taylor expanded around 0 52.3
if -4.1675890391810646e147 < b < -1.346684968652724e-176Initial program 7.1
Simplified7.1
rmApplied add-sqr-sqrt_binary64_16927.4
if -1.346684968652724e-176 < b < 2.8570753534361131e153Initial program 30.9
Simplified30.9
rmApplied flip--_binary64_173331.0
Simplified15.1
Simplified15.1
rmApplied *-un-lft-identity_binary64_170715.1
Applied times-frac_binary64_170213.3
Applied times-frac_binary64_17028.6
Simplified8.6
Simplified8.6
if 2.8570753534361131e153 < b Initial program 63.9
Simplified63.9
rmApplied flip--_binary64_173363.9
Simplified37.9
Simplified37.9
rmApplied *-un-lft-identity_binary64_170737.9
Applied times-frac_binary64_170237.7
Applied times-frac_binary64_170237.7
Simplified37.7
Simplified37.7
Taylor expanded around 0 32.5
Final simplification17.5
herbie shell --seed 2020270
(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)))