0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot e^{\sqrt[3]{{\left(\mathsf{fma}\left(2, \log im, \log \left(\frac{0.5}{re}\right)\right)\right)}^{3}}}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, 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 (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0)
(*
0.5
(sqrt (* 2.0 (exp (cbrt (pow (fma 2.0 (log im) (log (/ 0.5 re))) 3.0))))))
(* 0.5 (sqrt (* 2.0 (- (hypot re 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 ((sqrt((re * re) + (im * im)) - re) <= 0.0) {
tmp = 0.5 * sqrt(2.0 * exp(cbrt(pow(fma(2.0, log(im), log(0.5 / re)), 3.0))));
} else {
tmp = 0.5 * sqrt(2.0 * (hypot(re, im) - re));
}
return tmp;
}



Bits error versus re



Bits error versus im
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 59.0
Simplified52.2
Applied add-sqr-sqrt_binary6453.7
Applied fma-neg_binary6455.8
Applied add-exp-log_binary6456.3
Applied add-cube-cbrt_binary6456.6
Applied exp-prod_binary6456.6
Taylor expanded in im around 0 62.0
Simplified31.9
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 35.3
Simplified6.7
Final simplification10.6
herbie shell --seed 2022003
(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)))))