I'm developing my own Real Number class, and for that, I have to implement the Natural Logarithm function.
I've used Maclaurin series of Natural log with iteration of 300 or 500. The division method for my class is also defined by me, and user can get truly "unlimited" digits after the decimal point as the result of division (if exists).
Now, the Maclaurin series is converging very slowly. After 300 or 500 iterations, it is giving correct precision up to 15 or 16 digits. But in my class, user can set the number of digits after the decimal point for the answer of the natural log.
I searched in internet, and found two methods - Halley's Method and Newton's Method. I decided to go with Newton's method, but unable to determine a suitable initial guess to start the iteration.
I want a generalized way to get the initial guess for any Argument to the natural log function. One way I'm thinking about is, finding $n \in \mathbb{Z}$ such that $e^n \leq x < e^{n+1}$ to calculate $\ln(x)$ where $x>0$. But I want to avoid this because, again I'm using the Taylor Series to compute $e^x$ and it takes 300 iterations per computation.
Is there any other way to find a good initial guess? Please suggest me.
The suggestion by @LutzLehmann reduces the problem of computing $\log(x)$ to the interval $x \in [1,2]$. Here you can approximate $\log(x)$ using a linear function $$\phi(x) = a x + b.$$ It is not surprising that $a = \log(2)$ is a good choice but a short calculation will establish that the best polynomial with respect to the infinity norm is represented by $$ a = \log(2), \quad b = - \frac{1+ a + \log(a)}{2}.$$ The error function $e(x) = \log(x) - \phi(x)$ peaks at the endpoints of the interval and at $x=\frac{1}{a}$ and $$ | \log(x) - \phi(x) | \leq a + b \approx 2.98 \cdot 10^{-2}.$$ You will find that $x_0 = \phi(x)$ is a good initial guess for $\log(x)$ when $x \in [1,2]$.
If $|x| \leq \delta$ is sufficiently small, then you can approximate $e^x$ using a truncated Taylor series $$e^x \approx p_n(x) = \sum_{j=0}^n \frac{x^j}{j!}.$$ If $|x| > \delta$, but $|x| \leq 2^m \delta$ for an integer $m \ge 0$, then you can approximate $y = e^x$ as follows $$\begin{align} t &= x/2^m \\ e^t & \approx p_n(t) \\ z_0 &= p_n(t) \\ z_j &= z_{j-1}^2, \quad j=1,2,...,m. \end{align}$$ and $y \approx z_m$ will be a good approximation provided that $\delta$ is sufficiently small and $n$ is sufficiently large. You will it straightforward to compute $e^t$ with a small relative error when $t$ is small and positive. When $t$ is small and negative, then you can compute $e^t$ using $e^t = 1/e^{-t}$.