\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 1.413754253679529 \cdot 10^{-168}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;im \leq 1.6664187845870407 \cdot 10^{-131}:\\
\;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)}{\log base}\\
\mathbf{elif}\;im \leq 4.608408956128725 \cdot 10^{-66}:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log \left(-re\right)}}\\
\mathbf{elif}\;im \leq 3.5143106717443304 \cdot 10^{+63}:\\
\;\;\;\;0.5 \cdot \frac{\log \left(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 (<= im 1.413754253679529e-168)
(/ (log (- re)) (log base))
(if (<= im 1.6664187845870407e-131)
(/ (log (+ im (* 0.5 (/ (* re re) im)))) (log base))
(if (<= im 4.608408956128725e-66)
(/ 1.0 (/ (log base) (log (- re))))
(if (<= im 3.5143106717443304e+63)
(* 0.5 (/ (log (+ (* 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 (im <= 1.413754253679529e-168) {
tmp = log(-re) / log(base);
} else if (im <= 1.6664187845870407e-131) {
tmp = log(im + (0.5 * ((re * re) / im))) / log(base);
} else if (im <= 4.608408956128725e-66) {
tmp = 1.0 / (log(base) / log(-re));
} else if (im <= 3.5143106717443304e+63) {
tmp = 0.5 * (log((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 im < 1.41375425367952904e-168Initial program 32.7
Simplified32.7
Taylor expanded around -inf 4.4
Simplified4.4
if 1.41375425367952904e-168 < im < 1.6664187845870407e-131Initial program 17.9
Simplified17.9
Taylor expanded around 0 35.7
Simplified35.7
if 1.6664187845870407e-131 < im < 4.6084089561287249e-66Initial program 12.6
Simplified12.5
Taylor expanded around -inf 30.1
Simplified30.1
rmApplied clear-num_binary6430.1
if 4.6084089561287249e-66 < im < 3.5143106717443304e63Initial program 11.9
Simplified11.8
rmApplied pow1_binary6411.8
Applied log-pow_binary6411.8
Applied pow1_binary6411.8
Applied sqrt-pow1_binary6411.8
Applied log-pow_binary6411.8
Applied times-frac_binary6411.8
if 3.5143106717443304e63 < im Initial program 45.3
Simplified45.3
Taylor expanded around 0 6.7
Final simplification9.3
herbie shell --seed 2021118
(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))))