\sqrt{re \cdot re + im \cdot im}\begin{array}{l}
\mathbf{if}\;re \le -1.3108523098680432 \cdot 10^{59}:\\
\;\;\;\;-1 \cdot re\\
\mathbf{elif}\;re \le 3.7629938528630668 \cdot 10^{58}:\\
\;\;\;\;\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.3108523098680432e+59)) {
temp = (-1.0 * re);
} else {
double temp_1;
if ((re <= 3.762993852863067e+58)) {
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.3108523098680432e+59Initial program 46.3
Taylor expanded around -inf 12.2
if -1.3108523098680432e+59 < re < 3.762993852863067e+58Initial program 21.6
if 3.762993852863067e+58 < re Initial program 45.8
Taylor expanded around inf 12.3
Final simplification17.8
herbie shell --seed 2020058
(FPCore (re im)
:name "math.abs on complex"
:precision binary64
(sqrt (+ (* re re) (* im im))))