Commodore 2001-8 User Manual page 25

Table of Contents

Advertisement

parentheses which follow them. Parentheses define the particular value within an array which is to be
used in an expression.
A(D, 1) refers to the first character in the second row of a two-column array and is different from A, A$ and
A%. All may be specified in the same program. Specific definitions and memory allocation techniques
for each of the types of variables follows, but first let us address some examples of how one uses
a variable.
Equal is used in two ways: If encountered in an IF-THEN type of statement, equal means the standard
mathematical function: the value to the left of the expression is compared and must equal the value of
the right. Otherwise, when following a variable such as in the expression A =2
+
2,
=
means replace the
value in A with the resultant of the expression to the right.
Originally BASIC required the word LET before any variable assignment, but in PET the LET is optional
and may be omitted. A
=
2 is equivalent to LET A
=
2. The command CLR sets all variables in PET to zero.
To understand how variables operate in BASIC, try the following examples on your PET. Remember to
press RETURN after each command you enter.
CLR
?A
PET prints D.
Now type
A=2+2
?A
This time PET prints 4.
Now type
?B
PET prints O.
Now replace the value of B with twice the value in A, by typing
B=2"A
?B
PET prints 8.
Now change the value of A by typing
A=2+3
?A
PET prints 5. If you now type
?B
PET prints 8, the same value as before. Until we give a new expression for B or re-execute the one which
says B
=
2* A, the value of B will remain 8.
FLOATING POINT VARIABLES
BASIC always assumes operation, or operates totally, in floating point arithmetic. The:refore, each normal
variable is assigned space in memory for a standard floating point number.
Four bytes contain a binary representation of that precision. It gives us the capability of specifying about
9 digits precision of a decimal number. Accuracy of most calculations is limited to this representation.
Each variable is also assigned a 1-byte exponent limited to having a maximum value of
+
33.
Exponents
less thgan
-34
yield numbers too small to distinguish from zero.
STRING VARIABLES
A string variable can contain a function, whether it be a number, graphics character, or standard ASCII
character. There is a specific set of variables that allow extraction and packing of data into strings which
21

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents