Average Error: 32.5 → 18.5
Time: 17.2s
Precision: binary64
\[\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.0734375848046968 \cdot 10^{+70}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.6582413586913936 \cdot 10^{-215}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.901868561004965 \cdot 10^{-300}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re}{\frac{im}{re}}\right)}{\log base}\\ \mathbf{elif}\;re \leq 5.814525713456844 \cdot 10^{+84}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]
\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.0734375848046968 \cdot 10^{+70}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;re \leq -1.6582413586913936 \cdot 10^{-215}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\

\mathbf{elif}\;re \leq -7.901868561004965 \cdot 10^{-300}:\\
\;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re}{\frac{im}{re}}\right)}{\log base}\\

\mathbf{elif}\;re \leq 5.814525713456844 \cdot 10^{+84}:\\
\;\;\;\;\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 -1.0734375848046968e+70)
   (/ (log (- re)) (log base))
   (if (<= re -1.6582413586913936e-215)
     (/ (log (sqrt (+ (* re re) (* im im)))) (log base))
     (if (<= re -7.901868561004965e-300)
       (/ (log (+ im (* 0.5 (/ re (/ im re))))) (log base))
       (if (<= re 5.814525713456844e+84)
         (/ (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 <= -1.0734375848046968e+70) {
		tmp = log(-re) / log(base);
	} else if (re <= -1.6582413586913936e-215) {
		tmp = log(sqrt((re * re) + (im * im))) / log(base);
	} else if (re <= -7.901868561004965e-300) {
		tmp = log(im + (0.5 * (re / (im / re)))) / log(base);
	} else if (re <= 5.814525713456844e+84) {
		tmp = log(sqrt((re * re) + (im * im))) / log(base);
	} else {
		tmp = log(re) / log(base);
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if re < -1.07343758480469678e70

    1. Initial program 47.3

      \[\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}\]
    2. Simplified47.2

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around -inf 10.3

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot re\right)}}{\log base}\]

    if -1.07343758480469678e70 < re < -1.6582413586913936e-215 or -7.9018685610049649e-300 < re < 5.8145257134568444e84

    1. Initial program 21.7

      \[\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}\]
    2. Simplified21.6

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]

    if -1.6582413586913936e-215 < re < -7.9018685610049649e-300

    1. Initial program 32.9

      \[\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}\]
    2. Simplified32.9

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around 0 36.0

      \[\leadsto \frac{\log \color{blue}{\left(0.5 \cdot \frac{{re}^{2}}{im} + im\right)}}{\log base}\]
    4. Simplified35.9

      \[\leadsto \frac{\log \color{blue}{\left(im + 0.5 \cdot \frac{re}{\frac{im}{re}}\right)}}{\log base}\]

    if 5.8145257134568444e84 < re

    1. Initial program 49.4

      \[\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}\]
    2. Simplified49.3

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}\]
    3. Taylor expanded around inf 11.3

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{1}{re}\right)}{\log base}}\]
    4. Simplified11.3

      \[\leadsto \color{blue}{\frac{\log re}{\log base}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification18.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.0734375848046968 \cdot 10^{+70}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.6582413586913936 \cdot 10^{-215}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{elif}\;re \leq -7.901868561004965 \cdot 10^{-300}:\\ \;\;\;\;\frac{\log \left(im + 0.5 \cdot \frac{re}{\frac{im}{re}}\right)}{\log base}\\ \mathbf{elif}\;re \leq 5.814525713456844 \cdot 10^{+84}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log re}{\log base}\\ \end{array}\]

Reproduce

herbie shell --seed 2021176 
(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))))