I'm trying to find the result of $\log{x}$ (base 10) close to exact value in two digits with these methods:

The methods below are doing by hand. I appreciate you all who already give answers for computer method.

As suggested by Praktik Deoghare's answer

If number N (base 10) is n-digit then $$n-1 \leq \log_{10}(N) < n$$ Then logarithm can be approximated using $$\log_{10}(N) \approx n-1 + \frac{N}{10^{n} - 10^{n-1}}$$ Logarithm maps numbers from 10 to 100 in the range 1 to 2 so log of numbers near 50 is about 1.5. But this is only a linear approximation, good for mental calculation and toy projects but not that good for serious research.

This method is cool for me, but it's nearly close to exact value. $\log_{10}(53)$ is 1.7 and with that method results 1.58.

As suggested by Pedro Tamaroff's answer

One can get very good approximations by using $$\frac 1 2 \log \left|\frac{1+x}{1-x}\right| =x+\frac {x^3} 3+ \frac {x^5}5+\cdots$$ Say you want to get $\log{3}$. Then take $x=1/2$. Then you get $$\log 3 \approx 2\left( \frac 1 2 +\frac 1 {24} + \frac 1 {140} \right)=1.0976190\dots$$ The real value is $\log 3 \approx 1.098065476\dots$

This one is also cool for me, but it's to find natural logarithm, not base-10 logarithm.

As suggested by Kaleb's answer

This can be done by recourse to Taylor series. For $ln(x)$ centered at 1, i.e. where $0 < x \leq 2$: $$\ln(x)= \sum_{n=1}^\infty \frac{(x-1)^n}{n}= (x-1) - \frac{1}{2}(x-1)^2 + \frac{1}{3}(x-1)^3 + \frac{1}{4}(x-1)^4 + \cdots$$

The method is for calculating $ln(x)$, not $\log{x}$. I don't know the Taylor series for calculate $\log{x}$, especially when to find log result close to exact value in two digits (with similar method).

As suggested by Glenn's answer

The Wikipedia article "Generalized continued fraction" has a Khovanskiĭ-based algorithm that differs only in substituting x/y for z, and showing an intermediate step: $$\log \left( 1+\frac{x}{y} \right) = \cfrac{x} {y+\cfrac{1x} {2+\cfrac{1x} {3y+\cfrac{2x} {2+\cfrac{2x} {5y+\cfrac{3x} {2+\ddots}}}}}} $$

This method is very slow for me. When I stop at $3y$, the result (log calculation) is still far from the exact value.

Anyone who can improve all of the above methods so I can precisely get log result close to exact value in two digits?

  • 1
    $\begingroup$ What is the range you want to approximate? $\endgroup$ – grdgfgr Jun 7 '15 at 7:24
  • $\begingroup$ The formula for $\frac12\log \big|\frac{1+x}{1-x} \big|$ is also for the natural logarithm, not the base-10 logarithm. $\endgroup$ – Greg Martin Jun 7 '15 at 7:26
  • $\begingroup$ @grdgfgr For $x$ of $\log{x}$ is 1 until 100, especially prime numbers. $\endgroup$ – làntèrn Jun 7 '15 at 7:26
  • 1
    $\begingroup$ Could you explain exactly what your requirements are? If you're doing this by computer, why can't you just use the built-in logarithm function? And if you're doing it by hand, I would only ask why you are doing it by hand!? $\endgroup$ – Christopher A. Wong Jun 7 '15 at 7:58
  • 1
    $\begingroup$ Why. Got nothing better to do? $\endgroup$ – grdgfgr Jun 7 '15 at 8:11

Listing a few tricks that work for mental arithmetic. Mostly to get the OP to comment, whether this is at all what they expect. I write $\log$ for $\log_{10}$ to save a few keystrokes.

You need to memorize a few logarithms and play with those. We all have seen $\log 2\approx 0.30103$ enough many times to have memorized it. Consequently by mental arithmetic we get for example the following $$ \begin{aligned} \log4&=2\log2&\approx 0.602,\\ \log5&=\log(10/2)&\approx 0.699,\\ \log1.6&=\log(2^4/10)&\approx 0.204,\\ \log1.024&=\log(2^{10})-3&\approx 0.0103.\\ \end{aligned} $$ Using these is based on spotting numerical near matches.

You should also be aware of the first order Taylor series approximation $$ \log(1+x)\approx\frac{x}{\ln 10}\approx\frac{x}{2.3}\approx0.434 x, $$ which implies (plug in $x=0.01$) that if you change the value of $x$ by 1 per cent, then its logarithm changes by approximately $0.0043$.

As an example let's do $\log 53$ and $\log7$. Here $x=53$ is $6\%$ larger than $50$, so a first order approximation would be $$ \log53\approx\log 50+6\cdot 0.0043=\log(10^2/2)+6\cdot0.00434\approx 2-0.30103+0.0258\approx1.725. $$ With $7$ we can spot that $7^2=49$ is $2\%$ less than $50$, so $$\log 7=\frac12\,\log49\approx\frac12(2-0.301-2\cdot0.0043)\approx\frac{1.690}2=0.845. $$ Here the third decimal of $\log53$ is off by one, but $\log7$ has three correct digits - both well within your desired accuracy.

  • $\begingroup$ Thank you so much! You can understand my question exactly :-). How do you make the %? $\endgroup$ – làntèrn Jun 7 '15 at 9:59
  • $\begingroup$ Sorry, I mean how do you know that is 6% larger and 2% less? $\endgroup$ – làntèrn Jun 7 '15 at 10:02
  • $\begingroup$ $1$ is $2\%$ of $50$. This method really is better suited for mental arithmetic than any serious work. Something you can impress students with (or chicks you meet at a bar, if you think showing off with logarithms helps your cause). $\endgroup$ – Jyrki Lahtonen Jun 7 '15 at 10:05
  • $\begingroup$ Wow this method is very awesome for me! Is the change by 0.0043 always work for any number of log? Or is there a small method to get the 0.0043? $\endgroup$ – làntèrn Jun 7 '15 at 10:10
  • $\begingroup$ It comes from that Taylor series expansion: $0.0043\approx 0.434\cdot \dfrac1{100}$. That $1/100$ is, of course, $1$ percent. Caveat: if the percentage difference is larger the formula will quickly begin to lose accuracy. You always need a nearby reference point. $\endgroup$ – Jyrki Lahtonen Jun 7 '15 at 10:17

Is this good enough? It is within your specifications in 1 to 100

enter image description here

$$\frac{\frac{(x-10)^5 (137+30 \log (10))}{756000000}+\frac{(x-10)^4 (77+30 \log (10))}{2520000}+\frac{(x-10)^3 (47+30 \log (10))}{36000}+\frac{1}{450} (x-10)^2 (9+10 \log (10))+\frac{1}{20} (x-10) (2+5 \log (10))+\log (10)}{\frac{(x-10)^5}{25200000}+\frac{(x-10)^4}{84000}+\frac{(x-10)^3}{1200}+\frac{1}{45} (x-10)^2+\frac{x-10}{4}+1}$$

in plain text:

(Log[10]+1/20 (-10+x) (2+5 Log[10])+1/450 (-10+x)^2 (9+10 Log[10])+((-10+x)^3 (47+30 Log[10]))/36000+((-10+x)^4 (77+30 Log[10]))/2520000+((-10+x)^5 (137+30 Log[10]))/756000000)/(1+1/4 (-10+x)+1/45 (-10+x)^2+(-10+x)^3/1200+(-10+x)^4/84000+(-10+x)^5/25200000)

You can generate these yourself :


Click the A button

enter image description here

If you want base 10, you would want to use Log10[x]


You are going to use this syntax to tune it yourself:


Of course you have to you use a computer to actually evaluate this rational function. But if you already have a computer, why not just evaluate logx ?


There is a well-known trick based on the linearization of the logarithm that can be employed in a shockingly simple manner. However, the linearization is only "nice" for computing $\log_2(x)$, which on a computer is the only relevant logarithm anyways since all numbers are represented in base 2.

The algorithm is as follows: Let $x = 2^b (1 + m)$, where $b$ is a non-negative integer and $m \in [0,1)$. Let the floating point bit representation of $x$ be given by the concatenation of the binary strings $b$ and $m$. Then you can trivially approximate $\log_2(x)$ by the binary number $b.m$, which is merely just moving the position of the "dot" in the floating point bit representation. This is really just the statement that $\log_2(1 + m) \approx m$.

If you are willing to store a single precomputed value $\log_{2}(10)$, then from here you can trivially convert to a base 10 logarithm.

Example: Chose $x = 53_{10}$ (as represented as a decimal). Then in binary $x = 110101_{2}$, and hence $b = 101_{2}$ and $m = 10101_{2}$. Then in binary $\log_2(x)$ can be approximated by $b.m = 101.10101_{2} = 5.65625_{10}$, and then $\log_{10}(x) \approx 5.65625 / \log_2(10) = 1.7027$.

Summary: Let $x = 2^b (1 + m)$. Then $\log_{10}(x) \approx 0.30103_{10} \times (b.m)_{2}$.

For the slightly better version, see this Wikipedia description.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.