TITLE: How to calculate $\exp(-x)$ using Taylor series
QUESTION [7 upvotes]: We know that the Taylor series expansion of $e^x$ is
\begin{equation}
e^x = \sum\limits_{i=1}^{\infty}\frac{x^{i-1}}{(i-1)!}.
\end{equation} 
If I have to use this formula to evaluate $e^{-20}$, how should I check for convergence?
MATLAB gives $e^{-20} = 2.0612e-009$. But when I use this formula to calculate it, I get $4.1736e-009$. My answer becomes more inaccurate as I take $x = -30, -40 \cdots$. The reason is obvious. This is because as the number of terms in the Taylor series increases, the factorial becomes more and more inaccurate using MATLAB. 

How can I use Taylor series to get accurate values of $e^x$ in MATLAB?
How does MATLAB built in command "exp()" calculate the exponential?

REPLY [4 votes]: A standard technique, not particular to Matlab, is to exploit a function's symmetries to map its inputs to a more manageable range. The exponential function satisfies the symmetry $e^{a+b}=e^ae^b$, and it's easy to multiply floating-point numbers by powers of two. So do this:
$$\begin{eqnarray}
e^{-20}&=&2^{-20\lg e}\\
&\approx&2^{-28.854}\\
&=&2^{-29}\times2^{0.146}\\
&=&2^{-29}\times e^{0.146\log2}\\
&\approx&2^{-29}\times e^{0.101}
\end{eqnarray}$$
Now you can easily evaluate $e^{0.101\ldots}$ using the Taylor series.