0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\begin{array}{l}
t_0 := \sqrt{\sqrt{2}}\\
\mathbf{if}\;re \leq 2.352210546064473 \cdot 10^{+37}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\sqrt{0.5} \cdot \left(t_0 \cdot \left(im \cdot t_0\right)\right)\right) \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (sqrt 2.0))))
(if (<= re 2.352210546064473e+37)
(* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))
(* 0.5 (* (* (sqrt 0.5) (* t_0 (* im t_0))) (sqrt (/ 1.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 t_0 = sqrt(sqrt(2.0));
double tmp;
if (re <= 2.352210546064473e+37) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * ((sqrt(0.5) * (t_0 * (im * t_0))) * sqrt((1.0 / re)));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < 2.3522105460644728e37Initial program 33.0
Simplified6.1
if 2.3522105460644728e37 < re Initial program 59.0
Simplified39.2
Taylor expanded in im around 0 13.7
Applied add-sqr-sqrt_binary6413.3
Applied associate-*l*_binary6413.4
Final simplification7.7
herbie shell --seed 2022160
(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)))))