Use $\log(x)$ to calculate $\log(x+1)$

543 Views Asked by At

Given that I know the value of $\log(x)$, I would like to calculate the value of $\log(x+1)$ on a computer.

I know that I could use the Taylor expansion of $\log(1+x)$, but that uses $x$ rather than $\log(x)$. The reason I do not want to use $x$ directly is because $\log(x)$ can get low values such as $-1000$, and this will cause an underflow.

My question is if there is a way of directly relating $\log(x)$ to $\log(1+x)$?

2

There are 2 best solutions below

0
On BEST ANSWER

Given $y=\ln x$ and assuming double precision float arithmetic, you can safely approximate

  • $\ln(1+x)\approx0$ for $x<4\cdot 10^{-324}$, i.e., for $y<-745$.
  • $\ln(1+x)\approx x=e^y$ for $x<2^{-53}$ (that is, if $x^2\ll x$), i.e., for $y<-37$
  • $\ln(1+x)\approx \ln x+\frac1x=y+e^{-y}$ for $y>37$
  • and in the intermediate range just go ahead and compute $\ln(1+x)=\ln(1+e^y)$.

Actually, most CPUs have a builtin $\ln(1+x)$ suited for this problem

0
On

As $x$ is tiny, the Taylor development of $\log(1+x)$ is perfectly appropriate and the requested relation is

$$\log(1+x)\approx x=e^{\log(x)}.$$

You need to take the antilogarithm of the given logarithm.