0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -5.935554961352542 \cdot 10^{+109}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq -3.990259720622686 \cdot 10^{-110}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{elif}\;re \leq 3.229385886304382 \cdot 10^{-86}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{elif}\;re \leq 1.1214730224820804 \cdot 10^{-28} \lor \neg \left(re \leq 1.5600440620400777 \cdot 10^{+41}\right):\\
\;\;\;\;0.5 \cdot \left(\left(\sqrt{0.5} \cdot \left(im \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(im + 0.5 \cdot e^{\left(\log re + \log re\right) - \log im}\right) - 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
(if (<= re -5.935554961352542e+109)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re -3.990259720622686e-110)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))
(if (<= re 3.229385886304382e-86)
(* 0.5 (sqrt (* 2.0 im)))
(if (or (<= re 1.1214730224820804e-28)
(not (<= re 1.5600440620400777e+41)))
(* 0.5 (* (* (sqrt 0.5) (* im (sqrt 2.0))) (sqrt (/ 1.0 re))))
(*
0.5
(sqrt
(*
2.0
(-
(+ im (* 0.5 (exp (- (+ (log re) (log re)) (log im)))))
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 <= -5.935554961352542e+109) {
tmp = 0.5 * sqrt(2.0 * (re * -2.0));
} else if (re <= -3.990259720622686e-110) {
tmp = 0.5 * sqrt(2.0 * (sqrt((re * re) + (im * im)) - re));
} else if (re <= 3.229385886304382e-86) {
tmp = 0.5 * sqrt(2.0 * im);
} else if ((re <= 1.1214730224820804e-28) || !(re <= 1.5600440620400777e+41)) {
tmp = 0.5 * ((sqrt(0.5) * (im * sqrt(2.0))) * sqrt(1.0 / re));
} else {
tmp = 0.5 * sqrt(2.0 * ((im + (0.5 * exp((log(re) + log(re)) - log(im)))) - re));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < -5.93555496135254183e109Initial program 53.2
Taylor expanded around -inf 9.0
Simplified9.0
if -5.93555496135254183e109 < re < -3.99025972062268588e-110Initial program 16.3
rmApplied pow1_binary6416.3
if -3.99025972062268588e-110 < re < 3.22938588630438209e-86Initial program 28.8
Taylor expanded around 0 10.6
Simplified10.6
Taylor expanded around 0 11.2
Simplified11.2
rmApplied sqrt-unprod_binary6410.9
Simplified10.9
if 3.22938588630438209e-86 < re < 1.12147302248208e-28 or 1.5600440620400777e41 < re Initial program 55.7
Taylor expanded around 0 16.8
if 1.12147302248208e-28 < re < 1.5600440620400777e41Initial program 45.3
Taylor expanded around 0 30.3
Simplified30.3
rmApplied add-exp-log_binary6430.3
Applied add-exp-log_binary6430.3
Applied add-exp-log_binary6430.3
Applied prod-exp_binary6430.3
Applied div-exp_binary6430.3
Final simplification14.2
herbie shell --seed 2021131
(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)))))