0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;im \le -4.31226287577943336 \cdot 10^{124}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-\left(re + im\right)\right)}\\
\mathbf{elif}\;im \le -1.31798426233677 \cdot 10^{-105}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{\sqrt{re \cdot re + im \cdot im} + re}{im}}}\\
\mathbf{elif}\;im \le -5.84508579610625006 \cdot 10^{-260}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-\left(re + im\right)\right)}\\
\mathbf{elif}\;im \le 3.10359725716777497 \cdot 10^{-130}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-2 \cdot re\right)}\\
\mathbf{elif}\;im \le 7.78847036828617129 \cdot 10^{89}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{\sqrt{re \cdot re + im \cdot im} + re}{im}}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\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 ((im <= -4.312262875779433e+124)) {
temp = (0.5 * sqrt((2.0 * -(re + im))));
} else {
double temp_1;
if ((im <= -1.3179842623367683e-105)) {
temp_1 = (0.5 * sqrt((2.0 * (im / ((sqrt(((re * re) + (im * im))) + re) / im)))));
} else {
double temp_2;
if ((im <= -5.84508579610625e-260)) {
temp_2 = (0.5 * sqrt((2.0 * -(re + im))));
} else {
double temp_3;
if ((im <= 3.103597257167775e-130)) {
temp_3 = (0.5 * sqrt((2.0 * (-2.0 * re))));
} else {
double temp_4;
if ((im <= 7.788470368286171e+89)) {
temp_4 = (0.5 * sqrt((2.0 * (im / ((sqrt(((re * re) + (im * im))) + re) / im)))));
} else {
temp_4 = (0.5 * sqrt((2.0 * (im - re))));
}
temp_3 = temp_4;
}
temp_2 = temp_3;
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}



Bits error versus re



Bits error versus im
Results
if im < -4.312262875779433e+124 or -1.3179842623367683e-105 < im < -5.84508579610625e-260Initial program 49.8
rmApplied flip--56.9
Simplified53.6
Taylor expanded around -inf 25.3
if -4.312262875779433e+124 < im < -1.3179842623367683e-105 or 3.103597257167775e-130 < im < 7.788470368286171e+89Initial program 23.7
rmApplied flip--32.0
Simplified24.2
rmApplied unpow224.2
Applied associate-/l*24.2
if -5.84508579610625e-260 < im < 3.103597257167775e-130Initial program 41.2
Taylor expanded around -inf 36.6
if 7.788470368286171e+89 < im Initial program 49.7
Taylor expanded around 0 10.6
Final simplification24.3
herbie shell --seed 2020057
(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)))))