\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 -2.858304761937573 \cdot 10^{+156}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 8.08598480039997 \cdot 10^{+98}:\\
\;\;\;\;\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{c \cdot 2}{\sqrt{b \cdot b + a \cdot \left(c \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{c \cdot 2}{\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 -2.858304761937573e+156)
(if (>= b 0.0) (/ (- b) a) (/ (* c 2.0) (- (- b) b)))
(if (<= b 8.08598480039997e+98)
(if (>= b 0.0)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
(/ (* c 2.0) (- (sqrt (+ (* b b) (* a (* c -4.0)))) b)))
(if (>= b 0.0)
(* -0.5 (* 2.0 (- (/ b a) (/ c b))))
(/ (* c 2.0) (- (- 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 <= -2.858304761937573e+156) {
double tmp_1;
if (b >= 0.0) {
tmp_1 = -b / a;
} else {
tmp_1 = (c * 2.0) / (-b - b);
}
tmp = tmp_1;
} else if (b <= 8.08598480039997e+98) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -0.5 * ((b + sqrt((b * b) - (c * (a * 4.0)))) / a);
} else {
tmp_2 = (c * 2.0) / (sqrt((b * b) + (a * (c * -4.0))) - b);
}
tmp = tmp_2;
} else if (b >= 0.0) {
tmp = -0.5 * (2.0 * ((b / a) - (c / b)));
} else {
tmp = (c * 2.0) / (-b - b);
}
return tmp;
}









Bits error versus a









Bits error versus b









Bits error versus c
Results
| Alternative 1 | |
|---|---|
| Error | 14.8 |
| Cost | 8002 |
| Alternative 2 | |
|---|---|
| Error | 17.9 |
| Cost | 7746 |
| Alternative 3 | |
|---|---|
| Error | 18.1 |
| Cost | 7618 |
| Alternative 4 | |
|---|---|
| Error | 22.6 |
| Cost | 833 |
| Alternative 5 | |
|---|---|
| Error | 55.9 |
| Cost | 64 |
| Alternative 6 | |
|---|---|
| Error | 61.5 |
| Cost | 64 |


if b < -2.85830476193757307e156Initial program 38.1
Simplified38.1
Taylor expanded around -inf 1.5
Simplified1.5
Taylor expanded around inf 1.5
rmApplied *-un-lft-identity_binary64_781.5
Applied associate-*l*_binary64_191.5
Simplified1.5
Simplified1.5
if -2.85830476193757307e156 < b < 8.0859848003999694e98Initial program 8.8
Simplified8.8
rmApplied sub-neg_binary64_718.8
Simplified8.8
Simplified8.8
if 8.0859848003999694e98 < b Initial program 46.3
Simplified46.3
Taylor expanded around -inf 46.3
Simplified46.3
Taylor expanded around inf 4.0
Simplified4.0
Simplified4.0
Final simplification6.8
herbie shell --seed 2021040
(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)))))))