(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im) :precision binary64 (if (<= re 2.7128668689896868e+129) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* 0.5 (sqrt (* 2.0 (* 0.5 (/ (pow im 2.0) re)))))))
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 <= 2.7128668689896868e+129) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (0.5 * (pow(im, 2.0) / re))));
}
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 <= 2.7128668689896868e+129) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (0.5 * (Math.pow(im, 2.0) / re))));
}
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 <= 2.7128668689896868e+129: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = 0.5 * math.sqrt((2.0 * (0.5 * (math.pow(im, 2.0) / re)))) 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 <= 2.7128668689896868e+129) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(0.5 * Float64((im ^ 2.0) / re))))); 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 <= 2.7128668689896868e+129) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = 0.5 * sqrt((2.0 * (0.5 * ((im ^ 2.0) / re)))); 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, 2.7128668689896868e+129], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(0.5 * N[(N[Power[im, 2.0], $MachinePrecision] / re), $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 2.7128668689896868 \cdot 10^{+129}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(0.5 \cdot \frac{{im}^{2}}{re}\right)}\\
\end{array}



Bits error versus re



Bits error versus im
Results
if re < 2.71286686898968676e129Initial program 35.0
Simplified8.8
if 2.71286686898968676e129 < re Initial program 62.9
Simplified41.6
Taylor expanded in re around inf 31.4
Final simplification12.1
herbie shell --seed 2022137
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))