# How many iterations of Taylor series for n correct decimal digits

I'm using Taylor series to estimate trigonometric functions. So I need to know exactly how many iterations of Taylor series (say for sine) are needed for n decimal digits precision?
(I'm writing a calculator program)
• It also very dependent on the computing environment. Although $\sin(x)$ has an alternating Taylor series which is theroretically convergent for all real $x$, you will actually have numerical convergence only for small absolute values, for larger $x$ there must be cancellation, eg. for $x=42$ the largest term is about $10^{17}$, but $|\sin(x)|\le 1$! Therefore you will not get any correct digit with IEEE double! – gammatester Oct 10 '13 at 13:41
The answer depends heavily on the distance between the point where you are taking the Taylor series (presumably at$~0$) and the value$~x$ for which you want to compute $\sin x$. The larger $|x|$, the worse the performance of the Taylor series, and the more terms are needed for a reasonable approximation. You may of course use the periodicity of the sine function to limit $|x|$ (supposing $x$ is real) before invoking your approximation.
• You can work out a formula for the number of iterations needed given the coefficients of the Taylor series itself, the value of $|x|$, and the desired precision. In the practical range of application, evaluated terms of the Taylor series tend to $0$ at least as fast as a geometric progression, which means that the error is proportional to the first term not taken into account. If the geometric progression converges rapidly (ratio much less than$~1$), the size of that first omitted term itself is a fair estimate. – Marc van Leeuwen Oct 10 '13 at 13:25