# How to calculate $e^x$ with a standard calculator

Is there a simple method for calculating the $e^x$ ($x\in\mathbb{R}$) with a basic add/subtract/multiply/divide calculator that converges in reasonable time, preferably without having to memorize coefficients as in the case of the power series?

I've found one for nth roots with Newton iteration that's pretty much dead simple and I'd really like to know what else can be done.

EDIT: I'm not really that excited about approximation unless the end result is completely accurate. There are some good ideas here, but this answer is the simplest option for a full-accuracy result using only a +/-/×/÷ calculator.

I also have a strong preference for algorithms which can be directly evaluated step-by-step on such a calculator. Otherwise pencil and paper or an excellent memory must be exercised.

-
Something other than 2.71828 x 2.71828 x 2.71828 x .... ? (For x an integer.) –  Unreasonable Sin Aug 5 '11 at 16:53
Why not just do $1+x \left( 1+ \frac{x}{2} \left( 1+ \frac{x}{3} \left( 1+ \frac{x}{4} ( \cdots ) \right) \right) \right)$ to whatever depth strikes your mood? –  anon Aug 5 '11 at 16:58
How hard is it to memorize $\sum_{n = 0}^{\infty}\frac{x^n}{n!}$ ?? –  The Chaz 2.0 Aug 5 '11 at 16:58
What range for $x$ do you have in mind? –  lhf Aug 5 '11 at 17:00
@jnm2: $\exp(10^8)$ is around $1.5\times 10^{43,429,448}$. If you can do that on a standard calculator I'll eat my foot. Anyway, the form I posted (which is just the series expansion) converges slowly and is hardly good for large $x$. The form $(1+\frac{x}{n}+\frac{x^2}{2n^2})^n$ does slightly better and requires less button-pushing but still doesn't work for large $x$. I don't think you'll find any formula that's (a) easy to remember (b) feasible to type in and (c) able to approximate $e^x$ for large $x$ all at once. –  anon Aug 5 '11 at 23:01

This is what I would do to calculate $e^x$ with perfect 8-digit accuracy.

Take $\lfloor x\rfloor$ and $b = x - \lfloor x\rfloor$, the whole and fractional parts respectively. ($e^x = e^{\lfloor x \rfloor + (x - \lfloor x\rfloor)} = e^{\lfloor x \rfloor} e^{x - \lfloor x \rfloor}$)

1. Use the $(((b/4 + 1)b/3 + 1)b/2 + 1)b + 1$ pattern to calculate $e^{x - \lfloor x\rfloor}$. (If the fractional part of the exponent is .4 or less, only terms up to $b/7$ are needed for 8-digit accuracy. Worst-case scenario ($b \rightarrow 1$) terms up to $b/10$ are needed.) This method is easy to implement on a simple calculator, especially ones with a memory slot to quickly reinsert $b$.

2. When that is finished, multiply by $e$ ($\approx 2.71828183$ by memorization) and press the equals button $\lfloor x\rfloor$ times to repeat multiply. The result is $e^x$.

EDIT: I've analyzed the number of terms required for full accuracy. Here is the chart (click to view full image):

Basically, if terms up to $b/t$ are needed to fully calculate $e^x$ up to 8-digit precision (7 digits after the decimal point), accounting for rounding (the $\frac{1}{2}$ term), the relation between $x$ and $t$ is given by $\sqrt[t]{\frac{1}{2}10^{-7}t!} = x$. I've confirmed this by heuristics (aka real-life testing).

-
Why not use the closest integer in order to bound the fractional exponent by $1/2$? –  joriki Aug 6 '11 at 17:46
Extra complexity. Bounding it to $\frac{1}{2}$ only brings you down to the $b/8$ term which is close to 1 at the $b/10$ term. You'd have to remember to divide 1 by the answer at the end. –  jnm2 Aug 6 '11 at 17:53
${\frac {1680+840\,x+180\,{x}^{2}+20\,{x}^{3}+{x}^{4}}{1680-840\,x+180 \,{x}^{2}-20\,{x}^{3}+{x}^{4}}}$ is accurate to within about $1.3 \times 10^{-10}$ for $-1/2 < x < 1/2$. –  Robert Israel Aug 8 '11 at 17:12
That's good, I'll have to remember it. It's also hard to implement on the type of calculator I asked about. I'd need to remember too many things at once. –  jnm2 Aug 11 '11 at 2:31

To echo Robert's and lhf's comments, Padé works nicely for approximation purposes. The $[2,2]$ approximant is easily remembered, in particular:

$$\exp(z)\approx\frac{(z+3)^2+3}{(z-3)^2+3}$$

but of course it is trivial to generate higher-order approximants (yet the coefficients aren't as easy to remember).

Here then is how to make this approximation slightly more practical: this hinges on the usual identity

$$\exp(2z)=\exp(z)^2$$

The "repeated squaring" idea is as follows, for the case of $z > 0$:

1. Keep halving the argument $z$ until $|z| < 0.1$. Note how many times you halved the argument. Call it $n$.

2. Evaluate the $[2,2]$ approximant at this reduced argument.

3. Square the result of the previous step $n$ times.

The result of this should be good to eight or so digits. For negative argument, negate the argument first, apply the repeated squaring method, and reciprocate the result afterwards. ($\exp(-z)=\frac1{\exp(z)}$)

-
If (heresy!) your calculator can't retain memory and you have to write digits on paper... never, ever round!!! Retain all the digits you can retain. –  Ｊ. Ｍ. Aug 7 '11 at 5:22

If $x$ is not too big, you could try approximating $e^x$ as $(1 + x/n)^n$ for some large $n$ (not too huge, or you run into roundoff error). Somewhat better is $(1 + x/n + x^2/(2 n^2))^n$. For example, with $x = 1$ and $n = 1000$, $(1 + 1/1000 + 1/(2\cdot 1000^2))^{1000} \approx 2.718281376$; the correct value is $e = 2.717281828$.

[EDIT: ] If you don't want powers, you might try the continued fraction $$e^x = 1 + \cfrac{x}{1 - \cfrac{x}{2 + \cfrac{x}{3 - \cfrac{x}{2 + \cfrac{x}{5 - \cfrac{x}{2 + \cdots}}}}}}$$

-
The calculators I have seen that don't have $e^x$ also don't have $y^x$, so you would have to do the powers by multiplying. It would help to have the exponent be a power of 2. Some of these calculators even have an $x^2$ key. –  Ross Millikan Aug 5 '11 at 17:06
@Robert: Notice the difference in appearance between these two formats: $1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{1 + \cdots}}}$ and $1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cdots}}}$. The latter uses \cfrac instead of \frac. (I've edited your answer to use \cfrac.) –  Michael Hardy Aug 5 '11 at 17:53
The continued fraction looks interesting, but how would I use it with a simple calculator? –  jnm2 Aug 5 '11 at 22:42
@Michael Hardy: I didn't know. I use \dfrac instead: $1 + \dfrac{1}{1 + \dfrac{1}{1 + \dfrac{1}{1 + \cdots}}}$. –  Américo Tavares Aug 5 '11 at 22:57
@jnm2: Let's say you're using the basic Windows calculator, which has no algebraic precedence rules but does have a memory and a $1/x$ button. Then you can do something like this. [type x] MS / 2 $\pm$ + 5 / MR $1/x$ + 2 / MR $1/x$ $\pm$ + 3 / MR $1/x$ + 2 / MR $1/x$ $\pm$ + 1 / MR $1/x$ + 1 =. –  Robert Israel Aug 7 '11 at 17:54

-
Note that the Pade approximants with numerator of degree equal to or one more than the denominator are convergents of the continued fraction. –  Robert Israel Aug 5 '11 at 21:27
@Robert, yes, this is mentioned in en.wikipedia.org/wiki/… –  lhf Aug 5 '11 at 21:30

This is what the LL scales on your slide rule are for: http://en.wikipedia.org/wiki/Slide_rule#Logarithms_and_exponentials

But seriously, here is what I would do, demonstrated as an example. This method works for large $x$, doesn't require a lot of memorization, and doesn't require that your calculator have a $y^x$ key. It's designed to be particularly efficient on a calculator that has an $x^2$ key.

$e^{9.6}=e^8\times e^2 \times e^{-.4}\approx ((e^2)^2)^2\times e^2 \times (((1+(-.4)/8)^2)^2)^2\approx 1.46\times10^4$

The idea is to take the nearest integer to the exponent and express it in binary. Here, $10=2^3+2^1$. For large exponents, this greatly reduces the number of operations compared to what you'd need if you did simple repeated multiplication. Using the $(1+x/8)^8$ approximation gives a maximum error of 1.5%. You can reduce the error as much as needed by changing the 8 to a bigger power of 2.

-
That's actually a pretty good approximation. The only problem I foresee with using it on a standard calculator is that you now have to convert large $x$ to binary, which isn't always easy or quick by dividing by $2$ and removing remainders repeatedly. –  anon Aug 6 '11 at 0:02
Good point. A method that avoids the decimal-to-binary conversion is this: $e^{9.6}\approx(1+9.6/1024)^{1024}$, where the exponentiation to the power 1024 is accomplished by pressing the $x^2$ key 10 times. The disadvantage would be that its precision would be limited because of rounding of the base $1+x/2^n$. For a large exponent, if you want to do the binary-conversion method, the best technique is not repeated division by 2. You'd want to start by converting to some intermediate base like 16, and then take the base-16 digits and convert them to binary. –  Ben Crowell Aug 6 '11 at 0:06

I read this post a while ago, and since then I found an extremely good approximation for $e^x$

$e^x=1+\cfrac{2x}{2-x+\cfrac{x^2}{6+\cfrac{6x^2}{10+\cfrac{10x^2}{14+...}}}}$

Truncated here, this gives an error of less than $10^{-7}$ for $x\in(-1.27,1)$. Every additional row increases this range by about 0.4 on both sides, but by using the repeated squaring mentioned above, this is all you will need.

-
Very nice. Do you have a good mnemonic for punching calculator buttons in the right order? –  jnm2 Mar 26 at 19:13

Here is yet another method: you can still do the "repeated squaring" bit, but instead of using the series or continued fraction (equivalently, the Padé approximant) for the exponential function itself, you use either the series or the continued fraction for the function $\frac{\tanh\,x}{x}$. Either should converge slightly faster for small arguments (which you should have after halving the original argument the appropriate number of times) since only even powers of the argument occur in either of those expansions for $\frac{\tanh\,x}{x}$. The "doubling formula" now required is

$$\tanh\,2x=\frac{2\tanh\,x}{1+\tanh^2 x}$$

and after doing the appropriate number of doublings, the exponential function is easily recovered:

$$\exp\,x=\frac{1+\tanh\frac{x}{2}}{1-\tanh\frac{x}{2}}$$

-

Maybe the definition with the sums and factorials might be what you can use.

Or try Taylor Expansion; that works on a lot of stuff.

-
It's the same thing you know. –  Najib Idrissi Aug 5 '11 at 17:47
Oh, I did not look closely enough then. But really makes sense since there are powers in the definition formula. Sorrry. –  queueoverflow Aug 5 '11 at 19:15
No problem :) ! –  Najib Idrissi Aug 6 '11 at 7:11
In the 1970's, when four-function calculators were the norm, I made up a set of tables that fit onto a single A6 notepad page, which gives, $e^{0.n}$, down to $e^{0.00000n}$, which after, one uses $e^{0.00000xxxxxx}=1.000000xxxxxx$.
When this is constructed in decimal, one multiplies the trainlig $xxxxx$ by some value, before adding in the $1$. Otherwise, it's pretty much the same.