Chapter 5 - Functions
Mathematically, a function is a rule for giving a number (the result) in exchange for another (the argument,
or operand) & so is really a unary operation. The ZX81 has some of these built into it & their names are the
words written under the keys.
SQR
, for instance, is the familiar square root function, and
PRINT SQR
9
gives 3, the square root of 9. (To get
SQR
, you first press the
FUNCTION
key - shifted
NEWLINE
. This
changes the cursor to . Now press the
SQR
key (H):
SQR
appears on the screen and the cursor changes
back to . The same method works for all the words that are written underneath the keys, almost all of
which are function names.)
Try
PRINT SQR
2
You can test the accuracy of the answer by
PRINT SQR
2*
SQR
2
which ought to give 2. Note that both
SQR
s are worked out before the *, and in fact all functions (except
one -
NOT
) are worked out before the five operations +, -, *, / and **. Again, you can circumvent this rule
using brackets -
PRINT SQR
(2*2)
gives 2.
Here are some functions (there is a complete list in appendix C). If your maths is not up to
understanding some of these, it does not matter - you will still be able to use the computer.
* The trigonometrical functions. These work in radians, not degrees.
Using the jargon of the last chapter, all these except
PI
&
RND
are unary operations with priority 11. (
PI
&
RND
are nullary
operations, because they have no operands.)
SGN
The sign function (sometimes called signum to avoid confusion with
SIN
). The result is -1, 0 or +1
according as the argument is gative, zero or positive.
ABS
The absolute value, or modulus. The result is the argument made positive, so that
ABS
-3.2 =
ABS
3.2 = 3.2
SIN
*
COS
*
TAN
*
ASN
arcsin *
ACS
arccos *
ATN
arctan *
LN
natural logarithm (to base 2.718281828459045..., alias e)
EXP
exponential function
SQR
square root
INT
integer part. This always rounds down, so
INT
3.9 = 3 &
INT
-3.9 = -4. (An integer is a whole
number, possibly negative.)
PI
= 3.1415265358979..., the girth in cubits of a circle one cubit across.
PI
has no argument. (Only
ten digits of this are actually stored in the computer, & only eight will be displayed.)
RND
Neither has
RND
an argument. It yields a random number between 0 (which value it can take) & 1
(which it cannot).