COS

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: COS
Abbreviation: C Shift+O
Type: Function
Token code: 190/$BE
Handling routine
in BASIC ROM:
57956–57962
$E264–E26A
List of all BASIC keywords


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

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

COS is mathemathical function for the cosine calculation of a number (regarded as being in radians).

If the term given in the parentheses is non-numerical, the BASIC error ?TYPE MISMATCH ERROR IN line 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 IN line. Omitting the numeric argument results in a ?SYNTAX ERROR IN line.

ROM details[edit]

A mere seven bytes long, the handling routine in ROM is situated immediately before the much larger (73 bytes) handling routine for SIN: It exploits the mathematical identity which states that

cos x = sin(x+π/2)

The COS handling routine points to the floating point constant of π/2 (stored at 58080/$E2E0), then adds this figure to whatever argument is held in FAC, before falling through to the SIN handling routine.

Examples[edit]

PRINT COS(0) Screen: 1
?COS(23*π/180) (cos 23 degrees) Screen: .920504854
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