\sqrt{re \cdot re + im \cdot im}\begin{array}{l}
\mathbf{if}\;re \leq -2.8473355353767562 \cdot 10^{+116}:\\
\;\;\;\;-re\\
\mathbf{elif}\;re \leq 2.3232582542635886 \cdot 10^{+20}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}(FPCore (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
(FPCore (re im) :precision binary64 (if (<= re -2.8473355353767562e+116) (- re) (if (<= re 2.3232582542635886e+20) (sqrt (+ (* re re) (* im im))) re)))
double code(double re, double im) {
return ((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im))))));
}
double code(double re, double im) {
double tmp;
if ((re <= -2.8473355353767562e+116)) {
tmp = ((double) -(re));
} else {
double tmp_1;
if ((re <= 2.3232582542635886e+20)) {
tmp_1 = ((double) sqrt(((double) (((double) (re * re)) + ((double) (im * im))))));
} else {
tmp_1 = re;
}
tmp = tmp_1;
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < -2.8473355353767562e116Initial program Error: 54.7 bits
Taylor expanded around -inf Error: 8.6 bits
SimplifiedError: 8.6 bits
if -2.8473355353767562e116 < re < 232325825426358860000Initial program Error: 22.0 bits
if 232325825426358860000 < re Initial program Error: 40.4 bits
Taylor expanded around inf Error: 13.8 bits
Final simplificationError: 18.0 bits
herbie shell --seed 2020203
(FPCore (re im)
:name "math.abs on complex"
:precision binary64
(sqrt (+ (* re re) (* im im))))