\sqrt{re \cdot re + im \cdot im}\begin{array}{l}
\mathbf{if}\;im \leq 8.285117424768534 \cdot 10^{-162}:\\
\;\;\;\;-re\\
\mathbf{elif}\;im \leq 1.146743099784204 \cdot 10^{+114}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{else}:\\
\;\;\;\;im + 0.5 \cdot \frac{re}{\frac{im}{re}}\\
\end{array}(FPCore modulus (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
(FPCore modulus (re im)
:precision binary64
(if (<= im 8.285117424768534e-162)
(- re)
(if (<= im 1.146743099784204e+114)
(sqrt (+ (* re re) (* im im)))
(+ im (* 0.5 (/ re (/ im re)))))))double modulus(double re, double im) {
return sqrt((re * re) + (im * im));
}
double modulus(double re, double im) {
double tmp;
if (im <= 8.285117424768534e-162) {
tmp = -re;
} else if (im <= 1.146743099784204e+114) {
tmp = sqrt((re * re) + (im * im));
} else {
tmp = im + (0.5 * (re / (im / re)));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if im < 8.2851174247685339e-162Initial program 33.4
Taylor expanded around -inf 5.7
Simplified5.7
if 8.2851174247685339e-162 < im < 1.146743099784204e114Initial program 11.1
if 1.146743099784204e114 < im Initial program 53.8
Taylor expanded around 0 13.2
Simplified13.2
rmApplied associate-/l*_binary646.1
Final simplification7.6
herbie shell --seed 2021175
(FPCore modulus (re im)
:name "math.abs on complex"
:precision binary64
(sqrt (+ (* re re) (* im im))))