\[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\]
↓
\[\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{+155}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im}{re} \cdot \left(-im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\]
(FPCore (re im)
:precision binary64
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
↓
(FPCore (re im)
:precision binary64
(if (<= re -3.6e+155)
(* 0.5 (sqrt (* (/ im re) (- im))))
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
↓
double code(double re, double im) {
double tmp;
if (re <= -3.6e+155) {
tmp = 0.5 * sqrt(((im / re) * -im));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
↓
public static double code(double re, double im) {
double tmp;
if (re <= -3.6e+155) {
tmp = 0.5 * Math.sqrt(((im / re) * -im));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im):
return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
↓
def code(re, im):
tmp = 0
if re <= -3.6e+155:
tmp = 0.5 * math.sqrt(((im / re) * -im))
else:
tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im))))
return tmp
function code(re, im)
return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re))))
end
↓
function code(re, im)
tmp = 0.0
if (re <= -3.6e+155)
tmp = Float64(0.5 * sqrt(Float64(Float64(im / re) * Float64(-im))));
else
tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im)))));
end
return tmp
end
function tmp = code(re, im)
tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
end
↓
function tmp_2 = code(re, im)
tmp = 0.0;
if (re <= -3.6e+155)
tmp = 0.5 * sqrt(((im / re) * -im));
else
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
end
tmp_2 = tmp;
end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
↓
code[re_, im_] := If[LessEqual[re, -3.6e+155], N[(0.5 * N[Sqrt[N[(N[(im / re), $MachinePrecision] * (-im)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
↓
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{+155}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im}{re} \cdot \left(-im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 26.4 |
|---|
| Cost | 7640 |
|---|
\[\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
t_1 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{if}\;im \leq -1.1 \cdot 10^{-13}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -1.05 \cdot 10^{-137}:\\
\;\;\;\;\frac{im}{\sqrt{-re}} \cdot -0.5\\
\mathbf{elif}\;im \leq -6.6 \cdot 10^{-174}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 2.15 \cdot 10^{-283}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq 9.5 \cdot 10^{-235}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{-1}{re}}\right)\\
\mathbf{elif}\;im \leq 6.6 \cdot 10^{-80}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\]
| Alternative 2 |
|---|
| Error | 25.8 |
|---|
| Cost | 7376 |
|---|
\[\begin{array}{l}
t_0 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{if}\;im \leq -5.8 \cdot 10^{-177}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{elif}\;im \leq 1.4 \cdot 10^{-283}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 1.1 \cdot 10^{-234}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{-1}{re}}\right)\\
\mathbf{elif}\;im \leq 3.5 \cdot 10^{-78}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 26.0 |
|---|
| Cost | 7112 |
|---|
\[\begin{array}{l}
\mathbf{if}\;im \leq -3.1 \cdot 10^{-146}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\
\mathbf{elif}\;im \leq 7 \cdot 10^{-80}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\]
| Alternative 4 |
|---|
| Error | 25.7 |
|---|
| Cost | 7112 |
|---|
\[\begin{array}{l}
\mathbf{if}\;im \leq -3.2 \cdot 10^{-176}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{elif}\;im \leq 2 \cdot 10^{-77}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 26.3 |
|---|
| Cost | 6984 |
|---|
\[\begin{array}{l}
\mathbf{if}\;im \leq -1.6 \cdot 10^{-146}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\
\mathbf{elif}\;im \leq 6.2 \cdot 10^{-79}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 36.4 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;im \leq 1.35 \cdot 10^{-76}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 46.9 |
|---|
| Cost | 6720 |
|---|
\[0.5 \cdot \sqrt{im \cdot 2}
\]