The function $\coth(x) - 1/x$ has a removable singularity at 0. Its Taylor series is: $$ \coth(x) - 1/x = \frac{x}{3} - \frac{x^3}{45} + \frac{2x^5}{945} + \ldots $$ I would like to evaluate the first 3 terms of the Taylor series for $|x| \le \delta$, and just do a straight calculation of $\coth(x)$ and $x^{-1}$ for $|x|>\delta$.
What is the numerically correct way to select $\delta$, so the error over some fixed finite interval, say [-10,10], is minimized ?
Assume $x$ is 64-bit IEEE floating point, and that $\coth(x)$ is taken from a high-quality 64-bit precision library.
If $\delta$ is too small, then there is cancellation error for $x$ just a bit larger than $\delta$. And if $\delta$ is too large, then there is approximation error for $x$ just a bit less than $\delta$.
Surely there is a smart way to analyze this without using trial-and-error.
Added later: Thanks to @njuffa, I have learned that this is the Langevin function and that a different polynomial, or perhaps a continued fraction expansion, near 0 might be more accurate. So a more general question is: after an approximate formula near 0 is chosen, what is a good procedure for finding the best switch-over point $\delta$ ?