Pi

From C64-Wiki
(Redirected from π)
Jump to navigationJump to search
BASIC keyword
Keyword: π
Abbreviation:
Type: Constant
Token code: 255/$FF
Handling routine
in BASIC ROM:
44712
$AEA8
List of all BASIC keywords


Remark: This article describes the BASIC command π in BASIC V2 at the Commodore 64.

Type: Constant
General Programming-Syntax: π

Pi or π is a special numerical BASIC V2 constant with the value of 3.14159265.

This constant is attributed with the fastest possible evaluation of an expression consisting of a single value (even faster as "." as a degenerated writing for a zero). This can be useful for functions with a dummy parameter which have to be evaluated anyway (e.g. the POS display function).


Examples[edit | edit source]

PRINT π

Output: 3.14159265

BASIC ROM Value[edit | edit source]

Pi can not be represented exactly on a computer, so an approximation is used. The value used in C64 is: 0x82490FDAA1. Strangely, this not the closest approximation 0x82490FDAA2, not even the 2nd closest 0x82490FDAA3, but the third closest approximation.

Hex Constant Decimal Error Ranking
82490FDAA1 3.1415926525 -10.5e-10 3rd closest (used in C=64 BASIC)
82490FDAA2 3.1415926535 -1.2e-10 1st closest
3.1415926535897932384626…
82490FDAA3 3.1415926544 +8.1e-10 2nd closest
82490FDAA4 3.1415926553 +17.4e-10 4th closest

The C64 BASIC ROM also uses other constants internally for computing sin/cos/tan, like 2*PI and PI/2. On the other hand, these are represented correctly as 83490FDAA2 and 81490FDAA2 respectively.

Links[edit | edit source]

WP-W11.png Wikipedia: Pi


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