\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 -1.713079792545147 \cdot 10^{+122}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\
\mathbf{elif}\;re \leq -2.9841378285324807 \cdot 10^{-149}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\
\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 (<= re -1.713079792545147e+122)
(- (/ (log (/ -1.0 re)) (log base)))
(if (<= re -2.9841378285324807e-149)
(/ (log (sqrt (+ (* re re) (* im im)))) (log base))
(/ (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 (re <= -1.713079792545147e+122) {
tmp = -(log(-1.0 / re) / log(base));
} else if (re <= -2.9841378285324807e-149) {
tmp = log(sqrt((re * re) + (im * im))) / log(base);
} else {
tmp = log(im) / log(base);
}
return tmp;
}



Bits error versus re



Bits error versus im



Bits error versus base
Results
if re < -1.71307979254514689e122Initial program 55.8
Simplified55.8
Taylor expanded around -inf 4.4
if -1.71307979254514689e122 < re < -2.9841378285324807e-149Initial program 11.4
Simplified11.3
if -2.9841378285324807e-149 < re Initial program 32.2
Simplified32.2
Taylor expanded around 0 5.2
Final simplification6.9
herbie shell --seed 2021044
(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))))