0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \le 7.84862278851990408 \cdot 10^{68}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\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.848622788519904e+68)) {
temp = (0.5 * sqrt((2.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.848622788519904e+68Initial program 33.3
rmApplied hypot-def6.5
if 7.848622788519904e+68 < re Initial program 59.6
rmApplied flip--59.6
Simplified43.5
Simplified30.9
Final simplification11.2
herbie shell --seed 2020056 +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)))))