How do pocket calculators calculate exponents?

21.5k Views Asked by At

I'd like to know specifically how a pocket calculator (TI calculators also apply) calculates $e^{0.1}$, and what methods or algorithms pocket calculators use in order to produce their answer.

4

There are 4 best solutions below

0
On BEST ANSWER

I would be surprised if they actually used Taylor series. For example, the basic 80x87 "exponential" instruction is F2XM1 which computes $2^x-1$ for $0 \le x \le 0.5$. I don't think the implementation is documented, but if I were programming this, I might use a minimax polynomial or rational approximation: the following polynomial of degree $9$ approximates $2^x - 1$ on this interval with maximum error approximately $1.57 \times 10^{-17}$:

-0.15639e-16+(.69314718055995154416+(.24022650695869054994+
(0.55504108675285271942e-1+(0.96181289721472527028e-2
+(0.13333568212100120656e-2+(0.15403075872034576440e-3
+(0.15265399313676342402e-4+(0.13003468358428470167e-5
+0.12113766044841794408e-6*x)*x)*x)*x)*x)*x)*x)*x)*x

By contrast, the Maclaurin polynomial of the same degree has maximum error about $7.11 \times 10^{-12}$ on this interval.

3
On

Note that $e^{x}=\sum_{n=0}^{\infty} \frac{x^{n}}{n!}$ so if you want an approximation of $e^{x}$ you can just truncate the series.

$$e^{x}\approx \sum_{n=0}^{N} \frac{x^{n}}{n!}.$$

After some quick searching, it looks like series are probably not (usually) the best way to go. See the accepted answer here: https://stackoverflow.com/questions/15350856/which-method-to-implement-exp-function-in-c

0
On

The ultimate answer can only be given by the maker of the calculator, but there are several strategies:

  • The value can be calculated through the series expansion.
  • The value can be interpolated from a stored table.
  • The value can be reduced to the value of a smaller/larger argument by basic operations; for example $e^{2x} = (e^x)^2 = e^x\times e^x$.

In practice, a combination will likely be used. For large values (where the convergence of the series is slow), the value will likely be reduced to smaller arguments. Probably the calculator will also have stored the argument values beyond which overflow or underflow occurs, so for those the calculation can be skipped and an error (for overflow) or $0$ (for underflow) can be returned directly. For small values, Probably the series will be used directly, since it converges quickly. There might, however, also be a range of values where a lookup table is more efficient (that lookup table would then also be the "landing zone" for the large argument reduction). The interpolation would then probably again use the series expansion for the difference, using $e^{x+\delta}=e^xe^\delta$, where $x$ is the tabulated value and $\delta$ is the difference.

As a concrete example, the calulator could employ the following strategy:

  • Store a table of $e^n$ for $n=1$ to $100$.
  • For $\left|x\right| \le \frac12$, use the series directly. For $\frac12<x\le100.5$, use the series to calculate the factor to the nearest integer. For the corresponding negative argument, calculate the inverse.
  • For higher values of $x$, but below the overflow limit, use recursion and the mentioned exponential relations to calculate the value by iteration. One relatively efficient method it to go through the bits of the remaining summand, square for every digit, and multiply by $e$ for every $1$. But given the table, probably more efficient iterations could be done (for example, take the 64th power by repeated squaring, and multiply by the value for the argument represented by the corresponding 6 bits, read from the table).

Of course the actual algorithm chosen depends on how fast the processor is (that is, how much inefficiency can you afford), how much memory it has available (that is, a how large table can you afford to store) and how accurate the calculator calculates (more accuracy means both more series terms to calculate, and larger table entries).

0
On

A commonly used set of algorithms is known as CORDIC: COordinate Rotation DIgital Computer. Basically, it uses a bunch of bitshifts, adds, subtracts and look up tables. Its good for cases where you don't have hardware multipliers and what not.

You can also truncate series as well.

An interesting thing is that you can often do some math and identify which chip is used in a calculator. I believe datamath.org has some information on this.