\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}\;re \leq -2.880171495702805 \cdot 10^{+142}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;re \leq -6.968239497015886 \cdot 10^{-140}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\
\mathbf{elif}\;re \leq -2.0009587246036498 \cdot 10^{-216}:\\
\;\;\;\;\frac{0.5}{\log base} \cdot \left(-2 \cdot \log \left(\frac{-1}{re}\right)\right)\\
\mathbf{elif}\;re \leq 9.686995765174227 \cdot 10^{-282}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\mathbf{elif}\;re \leq 8.601619134334225 \cdot 10^{-221}:\\
\;\;\;\;\frac{0.5}{\frac{\log base}{-2 \cdot \log \left(\frac{-1}{im}\right)}}\\
\mathbf{elif}\;re \leq 2.148071380303255 \cdot 10^{+127}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log re}{\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 (<= re -2.880171495702805e+142)
(/ (log (- re)) (log base))
(if (<= re -6.968239497015886e-140)
(/ (log (sqrt (+ (* re re) (* im im)))) (log base))
(if (<= re -2.0009587246036498e-216)
(* (/ 0.5 (log base)) (* -2.0 (log (/ -1.0 re))))
(if (<= re 9.686995765174227e-282)
(/ (log im) (log base))
(if (<= re 8.601619134334225e-221)
(/ 0.5 (/ (log base) (* -2.0 (log (/ -1.0 im)))))
(if (<= re 2.148071380303255e+127)
(/ (log (sqrt (+ (* re re) (* im im)))) (log base))
(/ (log re) (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 (re <= -2.880171495702805e+142) {
tmp = log(-re) / log(base);
} else if (re <= -6.968239497015886e-140) {
tmp = log(sqrt((re * re) + (im * im))) / log(base);
} else if (re <= -2.0009587246036498e-216) {
tmp = (0.5 / log(base)) * (-2.0 * log(-1.0 / re));
} else if (re <= 9.686995765174227e-282) {
tmp = log(im) / log(base);
} else if (re <= 8.601619134334225e-221) {
tmp = 0.5 / (log(base) / (-2.0 * log(-1.0 / im)));
} else if (re <= 2.148071380303255e+127) {
tmp = log(sqrt((re * re) + (im * im))) / log(base);
} else {
tmp = log(re) / log(base);
}
return tmp;
}



Bits error versus re



Bits error versus im



Bits error versus base
Results
if re < -2.880171495702805e142Initial program 60.7
Simplified60.6
Taylor expanded around -inf 8.1
if -2.880171495702805e142 < re < -6.96823949701588615e-140 or 8.6016191343342254e-221 < re < 2.148071380303255e127Initial program 17.7
Simplified17.6
if -6.96823949701588615e-140 < re < -2.0009587246036498e-216Initial program 29.7
Simplified29.7
rmApplied pow1/2_binary64_15829.7
Applied log-pow_binary64_16729.7
Applied associate-/l*_binary64_2329.7
rmApplied associate-/r/_binary64_2429.7
Taylor expanded around -inf 44.1
if -2.0009587246036498e-216 < re < 9.6869957651742271e-282Initial program 30.4
Simplified30.4
Taylor expanded around 0 33.6
if 9.6869957651742271e-282 < re < 8.6016191343342254e-221Initial program 29.3
Simplified29.2
rmApplied pow1/2_binary64_15829.2
Applied log-pow_binary64_16729.2
Applied associate-/l*_binary64_2329.2
Taylor expanded around -inf 29.9
if 2.148071380303255e127 < re Initial program 57.3
Simplified57.3
Taylor expanded around inf 8.2
Final simplification18.8
herbie shell --seed 2021024
(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))))