0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \le 7.88870707244846019 \cdot 10^{181}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(1 \cdot \mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{{im}^{2} + 0}{re + \mathsf{hypot}\left(re, im\right)}}\\
\end{array}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 temp;
if ((re <= 7.88870707244846e+181)) {
temp = (0.5 * sqrt((2.0 * ((1.0 * hypot(re, im)) - re))));
} else {
temp = (0.5 * sqrt((2.0 * ((pow(im, 2.0) + 0.0) / (re + hypot(re, im))))));
}
return temp;
}



Bits error versus re



Bits error versus im
Results
if re < 7.88870707244846e+181Initial program 35.8
rmApplied *-un-lft-identity35.8
Applied sqrt-prod35.8
Simplified35.8
Simplified10.0
if 7.88870707244846e+181 < re Initial program 64.0
rmApplied flip--64.0
Simplified50.0
Simplified33.1
Final simplification12.3
herbie shell --seed 2020053 +o rules:numerics
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
(* 0.5 (sqrt (* 2 (- (sqrt (+ (* re re) (* im im))) re)))))