\log \left(\sqrt{re \cdot re + im \cdot im}\right)\begin{array}{l}
\mathbf{if}\;im \leq 3.5598012421053094 \cdot 10^{-159}:\\
\;\;\;\;\log \left(-re\right)\\
\mathbf{elif}\;im \leq 3.0994021608132516 \cdot 10^{+110}:\\
\;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(im + 0.5 \cdot \left(re \cdot \frac{re}{im}\right)\right)\\
\end{array}(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
(FPCore (re im)
:precision binary64
(if (<= im 3.5598012421053094e-159)
(log (- re))
(if (<= im 3.0994021608132516e+110)
(log (sqrt (+ (* re re) (* im im))))
(log (+ im (* 0.5 (* re (/ re im))))))))double code(double re, double im) {
return log(sqrt((re * re) + (im * im)));
}
double code(double re, double im) {
double tmp;
if (im <= 3.5598012421053094e-159) {
tmp = log(-re);
} else if (im <= 3.0994021608132516e+110) {
tmp = log(sqrt((re * re) + (im * im)));
} else {
tmp = log(im + (0.5 * (re * (re / im))));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if im < 3.55980124210530944e-159Initial program 32.1
Taylor expanded around -inf 4.5
if 3.55980124210530944e-159 < im < 3.0994021608132516e110Initial program 11.5
if 3.0994021608132516e110 < im Initial program 52.7
Taylor expanded around 0 12.9
Simplified12.9
rmApplied *-un-lft-identity_binary6412.9
Applied times-frac_binary645.4
Simplified5.4
Final simplification6.9
herbie shell --seed 2021118
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))