0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \le 1.07408121477840674 \cdot 10^{-17} \lor \neg \left(re \le 1.7538691601778439 \cdot 10^{51} \lor \neg \left(re \le 1.0065728139945699 \cdot 10^{120}\right)\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(1 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\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 <= 1.0740812147784067e-17) || !((re <= 1.753869160177844e+51) || !(re <= 1.0065728139945699e+120)))) {
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 < 1.0740812147784067e-17 or 1.753869160177844e+51 < re < 1.0065728139945699e+120Initial program 33.5
rmApplied *-un-lft-identity33.5
Applied *-un-lft-identity33.5
Applied distribute-lft-out--33.5
Simplified6.6
if 1.0740812147784067e-17 < re < 1.753869160177844e+51 or 1.0065728139945699e+120 < re Initial program 57.9
rmApplied flip--57.9
Simplified42.3
Simplified30.3
Final simplification11.6
herbie shell --seed 2020060 +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)))))