\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\begin{array}{l}
\mathbf{if}\;im \leq 1.658622391926313 \cdot 10^{-179}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log 10}\\
\mathbf{elif}\;im \leq 9.61360645752298 \cdot 10^{+33}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\
\end{array}(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
:precision binary64
(if (<= im 1.658622391926313e-179)
(- (/ (log (/ -1.0 re)) (log 10.0)))
(if (<= im 9.61360645752298e+33)
(*
(/ 0.5 (sqrt (log 10.0)))
(/ (log (+ (* re re) (* im im))) (sqrt (log 10.0))))
(* (/ 1.0 (sqrt (log 10.0))) (log (pow im (/ 1.0 (sqrt (log 10.0)))))))))double code(double re, double im) {
return log(sqrt((re * re) + (im * im))) / log(10.0);
}
double code(double re, double im) {
double tmp;
if (im <= 1.658622391926313e-179) {
tmp = -(log(-1.0 / re) / log(10.0));
} else if (im <= 9.61360645752298e+33) {
tmp = (0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) / sqrt(log(10.0)));
} else {
tmp = (1.0 / sqrt(log(10.0))) * log(pow(im, (1.0 / sqrt(log(10.0)))));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if im < 1.6586223919263131e-179Initial program 32.8
Taylor expanded around -inf 3.9
Simplified3.9
if 1.6586223919263131e-179 < im < 9.61360645752297957e33Initial program 12.8
rmApplied add-sqr-sqrt_binary64_78212.8
Applied pow1/2_binary64_84012.8
Applied log-pow_binary64_84912.8
Applied times-frac_binary64_76612.8
if 9.61360645752297957e33 < im Initial program 41.3
Taylor expanded around 0 7.4
rmApplied add-sqr-sqrt_binary64_7827.4
Applied pow1_binary64_8217.4
Applied log-pow_binary64_8497.4
Applied times-frac_binary64_7667.4
rmApplied add-log-exp_binary64_7997.4
Simplified7.1
Final simplification7.4
herbie shell --seed 2021060
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))