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

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)$?

• $\log{(1+x)}=\log{x}+\log{(1+1/x)}=\log{x}+1/x-1/x^2+...$ – Paul Feb 2 '16 at 17:20
• With values of $x$ as low as $e^{-1000}$, you can very very very safely use $\ln(1+x)=x$ ! – Yves Daoust Feb 2 '16 at 17:21
• @YvesDaoust Actually if $x = e^{-1000}$, $\log(1+x) = \log(1) = 0$... – Ring Ø Feb 2 '16 at 17:28
• @YvesDaoust Which makes me ask: Can the OP's data type represent $e^{-1000}\approx 5\cdot10^{-435}$ at all? That's 100 orders of magnitude smaller than the minimal nonzero double ... – Hagen von Eitzen Feb 2 '16 at 17:29
• $e^{-1000}$ is zero in double precision. – lisyarus Feb 2 '16 at 17:29

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

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.