ATN

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: ATN
Abbreviation: A Shift+T
Type: Function
Token code: 192/$C1
Handling routine
in BASIC ROM:
58126–58234
$E30E–E37A
List of all BASIC keywords


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

Type: Numeric Function
General Programming-Syntax: ATN(<numeric-expression>)

The numerical function ATN is a mathematical function that returns the arc tangent of a numeric value (the inverse function of TAN). The resulting value is the angle in radians of the given tangent. To convert radians into degrees use the formula (rad*180/π) where rad is the angle in radians.

If the term given in the parentheses is non-numerical, the BASIC error ?TYPE MISMATCH ERROR occurrs. Being a floating point argument, the term must be in the range of ±2.93873588·10−38 to ±1.70141183·1038. Exceeding these limits yields the BASIC error?OVERFLOW ERROR. Omitting the numeric argument or to many arguments results in a ?SYNTAX ERROR.

Implementation details[edit]

Let the parameter be X.

The inverse tangent is an odd function; that is, ATN(-X) = -ATN(X). The BASIC routine uses this property to simplify its calculations a bit. It saves the sign, and then computes AX = |X|.

If AX > 1, ATN uses the identity ATN(X) = π/2 - ATN(1/X) to limit AX to the interval [0, 1].

It uses this polynomial approximation to calculate ATN(AX) for 0 <= AX <= 1:

-6.8479391189*10-4 * T23 + 4.8509421558*10-3 * T21 - 1.6111701843*10-2 * T19 + 3.4209638048*10-2 * T17 - 5.4279132761*10-2 * T15 + 7.2457196540*10-2 * T13
- 8.9802395378*10-2 * T11 + 0.11093241343 * T9 - 0.14283980767 * T7 + 0.19999912049 * T5 - 0.33333331568 * T3 + T

and modifies the result according to the identities described above.

The derivation of the polynomial is not publicly known.

Examples[edit]

PRINT ATN(1)

Output: 0.785398163

PRINT ATN(1)*4

Output: 3.1415266
The result is equivalent to π, but differs slightly from π caused by the iterative internal calculation.


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