\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}\begin{array}{l}
\mathbf{if}\;b \leq -6.013298641369343 \cdot 10^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{a} \cdot \left(b \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.920249446757947 \cdot 10^{+26}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\end{array}(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
:precision binary64
(if (<= b -6.013298641369343e+153)
(if (>= b 0.0) (* (/ 2.0 a) (* b -0.5)) (/ (* 2.0 c) (- (- b) b)))
(if (<= b 2.920249446757947e+26)
(if (>= b 0.0)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
(/ (* 2.0 c) (- (sqrt (- (* b b) (* c (* a 4.0)))) b)))
(if (>= b 0.0)
(* -0.5 (* 2.0 (- (/ b a) (/ c b))))
(/ (* 2.0 c) (- (- b) b))))))double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-b - sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + sqrt((b * b) - ((4.0 * a) * c)));
}
return tmp;
}
double code(double a, double b, double c) {
double tmp;
if (b <= -6.013298641369343e+153) {
double tmp_1;
if (b >= 0.0) {
tmp_1 = (2.0 / a) * (b * -0.5);
} else {
tmp_1 = (2.0 * c) / (-b - b);
}
tmp = tmp_1;
} else if (b <= 2.920249446757947e+26) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * ((b + sqrt((b * b) - (c * (a * 4.0)))) / a);
} else {
tmp_2 = (2.0 * c) / (sqrt((b * b) - (c * (a * 4.0))) - b);
}
tmp = tmp_2;
} else if (b >= 0.0) {
tmp = -0.5 * (2.0 * ((b / a) - (c / b)));
} else {
tmp = (2.0 * c) / (-b - b);
}
return tmp;
}










Bits error versus a










Bits error versus b










Bits error versus c
Results
| Alternative 1 | |
|---|---|
| Error | 15.0 |
| Cost | 8323 |
| Alternative 2 | |
|---|---|
| Error | 17.7 |
| Cost | 7746 |
| Alternative 3 | |
|---|---|
| Error | 17.9 |
| Cost | 7618 |
| Alternative 4 | |
|---|---|
| Error | 22.3 |
| Cost | 833 |
| Alternative 5 | |
|---|---|
| Error | 22.4 |
| Cost | 833 |
| Alternative 6 | |
|---|---|
| Error | 56.1 |
| Cost | 64 |
| Alternative 7 | |
|---|---|
| Error | 61.6 |
| Cost | 64 |


if b < -6.01329864136934298e153Initial program 37.8
Simplified37.8
Taylor expanded around -inf 1.3
Simplified1.3
Taylor expanded around inf 1.3
Simplified1.3
rmApplied *-un-lft-identity_binary64_781.3
Applied times-frac_binary64_841.3
Applied associate-*r*_binary64_181.3
Simplified1.3
rmApplied *-commutative_binary64_91.3
Simplified1.3
if -6.01329864136934298e153 < b < 2.92024944675794714e26Initial program 8.9
Simplified8.9
Simplified8.9
if 2.92024944675794714e26 < b Initial program 35.7
Simplified35.7
Taylor expanded around -inf 35.7
Simplified35.7
Taylor expanded around inf 6.1
Simplified6.1
Simplified6.1
Final simplification6.9
herbie shell --seed 2021065
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))