Average Error: 31.2 → 7.4
Time: 7.5s
Precision: binary64
\[[re, im]=\mathsf{sort}([re, im])\]
\[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
\[\begin{array}{l} \mathbf{if}\;im \leq 1.658622391926313 \cdot 10^{-179}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log 10}\\ \mathbf{elif}\;im \leq 9.61360645752298 \cdot 10^{+33}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \end{array}\]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\begin{array}{l}
\mathbf{if}\;im \leq 1.658622391926313 \cdot 10^{-179}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log 10}\\

\mathbf{elif}\;im \leq 9.61360645752298 \cdot 10^{+33}:\\
\;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\

\end{array}
(FPCore (re im)
 :precision binary64
 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
(FPCore (re im)
 :precision binary64
 (if (<= im 1.658622391926313e-179)
   (- (/ (log (/ -1.0 re)) (log 10.0)))
   (if (<= im 9.61360645752298e+33)
     (*
      (/ 0.5 (sqrt (log 10.0)))
      (/ (log (+ (* re re) (* im im))) (sqrt (log 10.0))))
     (* (/ 1.0 (sqrt (log 10.0))) (log (pow im (/ 1.0 (sqrt (log 10.0)))))))))
double code(double re, double im) {
	return log(sqrt((re * re) + (im * im))) / log(10.0);
}
double code(double re, double im) {
	double tmp;
	if (im <= 1.658622391926313e-179) {
		tmp = -(log(-1.0 / re) / log(10.0));
	} else if (im <= 9.61360645752298e+33) {
		tmp = (0.5 / sqrt(log(10.0))) * (log((re * re) + (im * im)) / sqrt(log(10.0)));
	} else {
		tmp = (1.0 / sqrt(log(10.0))) * log(pow(im, (1.0 / sqrt(log(10.0)))));
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if im < 1.6586223919263131e-179

    1. Initial program 32.8

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Taylor expanded around -inf 3.9

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{-1}{re}\right)}{\log 10}}\]
    3. Simplified3.9

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

    if 1.6586223919263131e-179 < im < 9.61360645752297957e33

    1. Initial program 12.8

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary64_78212.8

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}}\]
    4. Applied pow1/2_binary64_84012.8

      \[\leadsto \frac{\log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\]
    5. Applied log-pow_binary64_84912.8

      \[\leadsto \frac{\color{blue}{0.5 \cdot \log \left(re \cdot re + im \cdot im\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\]
    6. Applied times-frac_binary64_76612.8

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

    if 9.61360645752297957e33 < im

    1. Initial program 41.3

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}\]
    2. Taylor expanded around 0 7.4

      \[\leadsto \frac{\log \color{blue}{im}}{\log 10}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt_binary64_7827.4

      \[\leadsto \frac{\log im}{\color{blue}{\sqrt{\log 10} \cdot \sqrt{\log 10}}}\]
    5. Applied pow1_binary64_8217.4

      \[\leadsto \frac{\log \color{blue}{\left({im}^{1}\right)}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\]
    6. Applied log-pow_binary64_8497.4

      \[\leadsto \frac{\color{blue}{1 \cdot \log im}}{\sqrt{\log 10} \cdot \sqrt{\log 10}}\]
    7. Applied times-frac_binary64_7667.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\log 10}} \cdot \frac{\log im}{\sqrt{\log 10}}}\]
    8. Using strategy rm
    9. Applied add-log-exp_binary64_7997.4

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \color{blue}{\log \left(e^{\frac{\log im}{\sqrt{\log 10}}}\right)}\]
    10. Simplified7.1

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \log \color{blue}{\left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.658622391926313 \cdot 10^{-179}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log 10}\\ \mathbf{elif}\;im \leq 9.61360645752298 \cdot 10^{+33}:\\ \;\;\;\;\frac{0.5}{\sqrt{\log 10}} \cdot \frac{\log \left(re \cdot re + im \cdot im\right)}{\sqrt{\log 10}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{\log 10}} \cdot \log \left({im}^{\left(\frac{1}{\sqrt{\log 10}}\right)}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021060 
(FPCore (re im)
  :name "math.log10 on complex, real part"
  :precision binary64
  (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))