(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
(let* ((t_0 (sqrt (- (* b b) (* c (* 4.0 a)))))
(t_1 (sqrt (hypot (sqrt (* c (* a -4.0))) b)))
(t_2 (- (- b) b))
(t_3 (/ (* 2.0 c) (- (- b) t_0))))
(if (<= b -124785765.50715955)
(if (>= b 0.0) t_3 (/ t_2 (* 2.0 a)))
(if (<= b 3.600333794359356e+83)
(if (>= b 0.0) t_3 (/ (- (* t_1 t_1) b) (* 2.0 a)))
(if (>= b 0.0) (/ (* 2.0 c) t_2) (/ (- t_0 b) (* 2.0 a)))))))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 t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double t_1 = sqrt(hypot(sqrt((c * (a * -4.0))), b));
double t_2 = -b - b;
double t_3 = (2.0 * c) / (-b - t_0);
double tmp_1;
if (b <= -124785765.50715955) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_3;
} else {
tmp_2 = t_2 / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 3.600333794359356e+83) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_3;
} else {
tmp_3 = ((t_1 * t_1) - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / t_2;
} else {
tmp_1 = (t_0 - b) / (2.0 * a);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - Math.sqrt(((b * b) - ((4.0 * a) * c))));
} else {
tmp = (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
return tmp;
}
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (c * (4.0 * a))));
double t_1 = Math.sqrt(Math.hypot(Math.sqrt((c * (a * -4.0))), b));
double t_2 = -b - b;
double t_3 = (2.0 * c) / (-b - t_0);
double tmp_1;
if (b <= -124785765.50715955) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_3;
} else {
tmp_2 = t_2 / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 3.600333794359356e+83) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_3;
} else {
tmp_3 = ((t_1 * t_1) - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / t_2;
} else {
tmp_1 = (t_0 - b) / (2.0 * a);
}
return tmp_1;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - math.sqrt(((b * b) - ((4.0 * a) * c)))) else: tmp = (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a) return tmp
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (4.0 * a)))) t_1 = math.sqrt(math.hypot(math.sqrt((c * (a * -4.0))), b)) t_2 = -b - b t_3 = (2.0 * c) / (-b - t_0) tmp_1 = 0 if b <= -124785765.50715955: tmp_2 = 0 if b >= 0.0: tmp_2 = t_3 else: tmp_2 = t_2 / (2.0 * a) tmp_1 = tmp_2 elif b <= 3.600333794359356e+83: tmp_3 = 0 if b >= 0.0: tmp_3 = t_3 else: tmp_3 = ((t_1 * t_1) - b) / (2.0 * a) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = (2.0 * c) / t_2 else: tmp_1 = (t_0 - b) / (2.0 * a) return tmp_1
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); else tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)); end return tmp end
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) t_1 = sqrt(hypot(sqrt(Float64(c * Float64(a * -4.0))), b)) t_2 = Float64(Float64(-b) - b) t_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)) tmp_1 = 0.0 if (b <= -124785765.50715955) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_3; else tmp_2 = Float64(t_2 / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 3.600333794359356e+83) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_3; else tmp_3 = Float64(Float64(Float64(t_1 * t_1) - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / t_2); else tmp_1 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end return tmp_1 end
function tmp_2 = code(a, b, c) tmp = 0.0; 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); end tmp_2 = tmp; end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (4.0 * a)))); t_1 = sqrt(hypot(sqrt((c * (a * -4.0))), b)); t_2 = -b - b; t_3 = (2.0 * c) / (-b - t_0); tmp_2 = 0.0; if (b <= -124785765.50715955) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_3; else tmp_3 = t_2 / (2.0 * a); end tmp_2 = tmp_3; elseif (b <= 3.600333794359356e+83) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = t_3; else tmp_4 = ((t_1 * t_1) - b) / (2.0 * a); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = (2.0 * c) / t_2; else tmp_2 = (t_0 - b) / (2.0 * a); end tmp_5 = tmp_2; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[Sqrt[N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[((-b) - b), $MachinePrecision]}, Block[{t$95$3 = N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -124785765.50715955], If[GreaterEqual[b, 0.0], t$95$3, N[(t$95$2 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 3.600333794359356e+83], If[GreaterEqual[b, 0.0], t$95$3, N[(N[(N[(t$95$1 * t$95$1), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / t$95$2), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]]]]
\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}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_1 := \sqrt{\mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)}\\
t_2 := \left(-b\right) - b\\
t_3 := \frac{2 \cdot c}{\left(-b\right) - t_0}\\
\mathbf{if}\;b \leq -124785765.50715955:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;\frac{t_2}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.600333794359356 \cdot 10^{+83}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 \cdot t_1 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{2 \cdot a}\\
\end{array}



Bits error versus a



Bits error versus b



Bits error versus c
Results
if b < -124785765.507159546Initial program 32.1
Taylor expanded in b around -inf 8.3
if -124785765.507159546 < b < 3.60033379435935626e83Initial program 9.6
Applied add-sqr-sqrt_binary649.7
Simplified12.1
Simplified11.4
if 3.60033379435935626e83 < b Initial program 28.0
Taylor expanded in b around inf 3.8
Final simplification8.8
herbie shell --seed 2022129
(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))))