\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}\begin{array}{l}
\mathbf{if}\;im \leq -3.912067078968373 \cdot 10^{+109}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{-2 \cdot \log \left(\frac{-1}{im}\right)}}\\
\mathbf{elif}\;im \leq -3.9713846065782325 \cdot 10^{-292}:\\
\;\;\;\;\frac{\log \left(\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}\right)}{\log base}\\
\mathbf{elif}\;im \leq 8.462466084530418 \cdot 10^{-206}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;im \leq 3.45516307946585 \cdot 10^{+57}:\\
\;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}(FPCore (re im base) :precision binary64 (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
(FPCore (re im base)
:precision binary64
(if (<= im -3.912067078968373e+109)
(/ 0.5 (/ (log base) (* -2.0 (log (/ -1.0 im)))))
(if (<= im -3.9713846065782325e-292)
(/
(log
(*
(sqrt (sqrt (+ (* re re) (* im im))))
(sqrt (sqrt (+ (* re re) (* im im))))))
(log base))
(if (<= im 8.462466084530418e-206)
(/ (log (- re)) (log base))
(if (<= im 3.45516307946585e+57)
(* (/ 0.5 (log base)) (log (+ (* re re) (* im im))))
(/ (log im) (log base)))))))double code(double re, double im, double base) {
return ((log(sqrt((re * re) + (im * im))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
double code(double re, double im, double base) {
double tmp;
if (im <= -3.912067078968373e+109) {
tmp = 0.5 / (log(base) / (-2.0 * log(-1.0 / im)));
} else if (im <= -3.9713846065782325e-292) {
tmp = log(sqrt(sqrt((re * re) + (im * im))) * sqrt(sqrt((re * re) + (im * im)))) / log(base);
} else if (im <= 8.462466084530418e-206) {
tmp = log(-re) / log(base);
} else if (im <= 3.45516307946585e+57) {
tmp = (0.5 / log(base)) * log((re * re) + (im * im));
} else {
tmp = log(im) / log(base);
}
return tmp;
}



Bits error versus re



Bits error versus im



Bits error versus base
Results
if im < -3.9120670789683728e109Initial program 53.8
Simplified53.8
rmApplied pow1/2_binary64_15853.8
Applied log-pow_binary64_16753.8
Applied associate-/l*_binary64_2353.8
Taylor expanded around -inf 9.5
if -3.9120670789683728e109 < im < -3.9713846065782325e-292Initial program 22.5
Simplified22.4
rmApplied add-sqr-sqrt_binary64_10022.4
if -3.9713846065782325e-292 < im < 8.4624660845304181e-206Initial program 31.2
Simplified31.1
Taylor expanded around -inf 32.9
if 8.4624660845304181e-206 < im < 3.45516307946585019e57Initial program 19.5
Simplified19.4
rmApplied pow1/2_binary64_15819.4
Applied log-pow_binary64_16719.4
Applied associate-/l*_binary64_2319.4
rmApplied associate-/r/_binary64_2419.4
if 3.45516307946585019e57 < im Initial program 45.3
Simplified45.3
Taylor expanded around 0 10.3
Final simplification18.2
herbie shell --seed 2021021
(FPCore (re im base)
:name "math.log/2 on complex, real part"
:precision binary64
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))