\sqrt{re \cdot re + im \cdot im}\begin{array}{l}
\mathbf{if}\;re \le -1.42313293869710733 \cdot 10^{141}:\\
\;\;\;\;-1 \cdot re\\
\mathbf{elif}\;re \le 2.55702876926703994 \cdot 10^{101}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}double code(double re, double im) {
return sqrt(((re * re) + (im * im)));
}
double code(double re, double im) {
double temp;
if ((re <= -1.4231329386971073e+141)) {
temp = (-1.0 * re);
} else {
double temp_1;
if ((re <= 2.55702876926704e+101)) {
temp_1 = sqrt(((re * re) + (im * im)));
} else {
temp_1 = re;
}
temp = temp_1;
}
return temp;
}



Bits error versus re



Bits error versus im
Results
if re < -1.4231329386971073e+141Initial program 60.5
Taylor expanded around -inf 8.0
if -1.4231329386971073e+141 < re < 2.55702876926704e+101Initial program 20.8
if 2.55702876926704e+101 < re Initial program 51.6
Taylor expanded around inf 9.2
Final simplification17.1
herbie shell --seed 2020066
(FPCore (re im)
:name "math.abs on complex"
:precision binary64
(sqrt (+ (* re re) (* im im))))