# Function

From C64-Wiki

A **function** is similair in mathematics also in IT a mathematical formula, which allocate each X value a Y value.

X = -1 : PRINT ABS(X)Screen / output: 1

Also subroutines can be a function, if this routine returns a value (of course in variables). In the Commodore BASIC aren't needed returns with variables, because all variables are used in the whole BASIC program.

10 A = 10: B = 5 20 GOSUB 100 30 PRINT A, B 99 END 100 REM *** Change function *** 101 C = A : A = B : B = C : C = 0: RETURNScreen / output: 5 10

The BASIC V2 of the C64 has this basically mathemathical functions like ABS, ATN, COS, EXP, INT, LOG, SGN, SIN, SQR and TAN.

A few special functions, which returns also a numeric value:

- RND used for random numbers
- DEF for defining own mathematical functions and FN for using or starting this definded function
- USR for handover of numbers into a machine language program or back in BASIC out of an assembler routine
- PEEK for peeking a memory adress
- FRE for showing the free (unused) RAM memory in BASIC V2

Also a few functions for string handling or converting:

- Numeric values from chars: ASC, LEN, VAL
- Chars from a number: CHR$, STR$
- Cutting chars or parts of strings from strings: LEFT$, MID$, RIGHT$

Cursor functions: