EXP

 BASIC keyword Keyword: EXP Abbreviation: E Shift+X Type: Function Token code: 189/\$BD Handling routinein BASIC ROM: 49133–57410\$BFED–E042 List of all BASIC keywords

Remark: This article describes the BASIC-Command EXP in BASIC V2 at the Commodore 64.

```Type: Numeric Function
General Programming-Syntax: EXP(<Number>)
```

EXP is a mathemathical function that evaluates the inverse natural LOG of the argument. That is, the argument X is applied as an exponent to e(2.71828183). So EXP(X) = eX.

Arguments in excess of 89.0296919 result in the BASIC error ?OVERFLOW ERROR IN line. Arguments less than -89.0296919 evaluate to 0.

When the argument doesn't evaluate to a number, the BASIC error ?TYPE MISMATCH ERROR IN line occurs. When the numeric argument is absent, it displays a ?SYNTAX ERROR IN line.

Examples

```PRINT EXP(0) Screen: 1
PRINT EXP(-1) Screen: 0.367879441
PRINT EXP(1) Screen: 2.71828183
```

Implementation

The EXP function uses the identity:

ex = 2x * log2(e)

Let the parameter be X. EXP first calculates T = X * log2(e). It then separates T into an integer N and a fraction TF, such that N + TF = T and 0 <= TF < 1.

It then calculates 2TF by the polynomial approximation:

2.1498763701*10-5 * TF7 + 1.4352314037*10-4 * TF6 + 1.3422634825*10-3 * TF5 + 9.6140170135*10-3 * TF4 + 5.5505126860*10-2 * TF3 + 0.24022638460 * TF2 + 0.69314718618 * TF + 1.0

It then adds the integer N, calculated above, to the exponent of the result, effectively multiplying it by 2N. The result is 2T, which is equal to eX.

The derivation of the polynomial is not publicly known.

BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR\$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT\$ | LEN | LET | LIST | LOAD | LOG | MID\$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT\$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR\$ | SYS | TAB | TAN | THEN | TIME/TI | TIME\$/TI\$ | TO | USR | VAL | VERIFY | WAIT