\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\end{array}\begin{array}{l}
\mathbf{if}\;b \leq -4.260328883394221 \cdot 10^{+153} \lor \neg \left(b \leq 1.4016155324368643 \cdot 10^{+68}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
:precision binary64
(if (or (<= b -4.260328883394221e+153) (not (<= b 1.4016155324368643e+68)))
(if (>= b 0.0) (* -2.0 (/ c (+ b b))) (/ (- (- b) b) (* a 2.0)))
(if (>= b 0.0)
(* -2.0 (/ c (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))))double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - sqrt((b * b) - ((4.0 * a) * c)));
} else {
tmp = (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
return tmp;
}
double code(double a, double b, double c) {
double tmp;
if ((b <= -4.260328883394221e+153) || !(b <= 1.4016155324368643e+68)) {
double tmp_1;
if (b >= 0.0) {
tmp_1 = -2.0 * (c / (b + b));
} else {
tmp_1 = (-b - b) / (a * 2.0);
}
tmp = tmp_1;
} else if (b >= 0.0) {
tmp = -2.0 * (c / (b + sqrt((b * b) - (c * (a * 4.0)))));
} else {
tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
}
return tmp;
}












Bits error versus a












Bits error versus b












Bits error versus c
Results
| Alternative 1 | |
|---|---|
| Error | 6.5 |
| Cost | 8644 |
| Alternative 2 | |
|---|---|
| Error | 9.6 |
| Cost | 8009 |
| Alternative 3 | |
|---|---|
| Error | 9.6 |
| Cost | 8516 |
| Alternative 4 | |
|---|---|
| Error | 17.7 |
| Cost | 7874 |
| Alternative 5 | |
|---|---|
| Error | 17.7 |
| Cost | 7746 |
| Alternative 6 | |
|---|---|
| Error | 18.0 |
| Cost | 7618 |
| Alternative 7 | |
|---|---|
| Error | 22.6 |
| Cost | 833 |
| Alternative 8 | |
|---|---|
| Error | 56.5 |
| Cost | 64 |
| Alternative 9 | |
|---|---|
| Error | 61.6 |
| Cost | 64 |

if b < -4.2603288833942209e153 or 1.40161553243686431e68 < b Initial program 38.2
Simplified38.2
Taylor expanded around -inf 19.8
Simplified19.8
Taylor expanded around inf 2.9
Simplified2.9
if -4.2603288833942209e153 < b < 1.40161553243686431e68Initial program 8.7
Simplified8.7
Simplified8.7
Final simplification6.5
herbie shell --seed 2021044
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))