(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
(let* ((t_0 (* c (/ a b)))
(t_1 (sqrt (+ (* b b) (* c (* a -4.0)))))
(t_2 (/ (* c 2.0) (- t_1 b)))
(t_3 (/ (- (- b) t_1) (* a 2.0))))
(if (<= b -2.5e+121)
(if (>= b 0.0) t_3 (/ (* c 2.0) (- (- (* 2.0 t_0) b) b)))
(if (<= b 2.4e+103)
(if (>= b 0.0) t_3 t_2)
(if (>= b 0.0) (/ (- (- b) (fma -2.0 t_0 b)) (* a 2.0)) t_2)))))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 t_0 = c * (a / b);
double t_1 = sqrt(((b * b) + (c * (a * -4.0))));
double t_2 = (c * 2.0) / (t_1 - b);
double t_3 = (-b - t_1) / (a * 2.0);
double tmp_1;
if (b <= -2.5e+121) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_3;
} else {
tmp_2 = (c * 2.0) / (((2.0 * t_0) - b) - b);
}
tmp_1 = tmp_2;
} else if (b <= 2.4e+103) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_3;
} else {
tmp_3 = t_2;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (-b - fma(-2.0, t_0, b)) / (a * 2.0);
} else {
tmp_1 = t_2;
}
return tmp_1;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end return tmp end
function code(a, b, c) t_0 = Float64(c * Float64(a / b)) t_1 = sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) t_2 = Float64(Float64(c * 2.0) / Float64(t_1 - b)) t_3 = Float64(Float64(Float64(-b) - t_1) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -2.5e+121) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_3; else tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(Float64(2.0 * t_0) - b) - b)); end tmp_1 = tmp_2; elseif (b <= 2.4e+103) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_3; else tmp_3 = t_2; end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(Float64(-b) - fma(-2.0, t_0, b)) / Float64(a * 2.0)); else tmp_1 = t_2; end return tmp_1 end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 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], 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]]
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[((-b) - t$95$1), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.5e+121], If[GreaterEqual[b, 0.0], t$95$3, N[(N[(c * 2.0), $MachinePrecision] / N[(N[(N[(2.0 * t$95$0), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.4e+103], If[GreaterEqual[b, 0.0], t$95$3, t$95$2], If[GreaterEqual[b, 0.0], N[(N[((-b) - N[(-2.0 * t$95$0 + b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]]
\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}
t_0 := c \cdot \frac{a}{b}\\
t_1 := \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\\
t_2 := \frac{c \cdot 2}{t_1 - b}\\
t_3 := \frac{\left(-b\right) - t_1}{a \cdot 2}\\
\mathbf{if}\;b \leq -2.5 \cdot 10^{+121}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(2 \cdot t_0 - b\right) - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{+103}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(-2, t_0, b\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
if b < -2.50000000000000004e121Initial program 34.0
Taylor expanded in b around -inf 6.8
Simplified2.1
if -2.50000000000000004e121 < b < 2.3999999999999998e103Initial program 8.6
if 2.3999999999999998e103 < b Initial program 47.5
Taylor expanded in b around inf 10.0
Simplified3.7
Final simplification6.5
herbie shell --seed 2022185
(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)))))))