Sinclair ZX81 User Manual page 13

Hide thumbs Also See for ZX81:
Table of Contents

Advertisement

The trigonometrical functions, & EXP , LN & SQR , are generally calculated to 8 digits accuracy.
RND & RAND : These are both on the same key, but whereas RND is a function, RAND is a keyword, like
PRINT . RAND is used for controlling the randomness of RND .
RND is not truly random, but follows a fixed sequence of 65536 numbers that happen to be so jumbled
up as to appear random ( RND is pseudo-random). You can use RAND to start RND off at a definite place
in this sequence by typing RAND , & then a number between 1 & 65535, & then NEWLINE . It's not so
important to know where a given number starts RND off, as that the same number after RAND will always
start RND off at the same place. For instance, type
RAND 1
(& NEWLINE )
& then
PRINT RND
& type both these in turn several times. (Remember to use FUNCTION to get RND .) The answer from RND
will always be 0.0022735596, not a very random sequence.
RAND 0
(or you can miss out the 0) acts slightly differently: it judges where to srart RND off by how long the
television has been on, & this should be genuinely random.
Note : In some dialects of BASIC you must always enclose the arguments of a function on brackets. This is
not the case in ZX81 8K BASIC.
Summary
Starement: RAND
Functions: SGN . ABS , SIN , COS , TAN , ASN , ACS , ATN , LN , EXP , SQR , INT , PI , RND
FUNCTION
Exercises
1. To get common logorithms (to base 10), which are what you'd look up in log tables, divide the natural
logarithm by LN 10. For instance, to find log 2,
PRINT LN 2/ LN 10
which gives the answer 0.30103.
Try doing multiplication & division using logs, using the ZX81 as a set of log tables in this way (for
antilogs, see chapter 2, exercise 3). Check the answer using * and / - which are easier, quicker, more
accurate, & much to be preferred.
2. EXP & LN are mutually inverse functions in the same sense that if you apply one & then the other, you
get back to your original number. For instance,
LN EXP 2 = EXP LN 2 = 2
The same also holds for SIN & ASN , for COS & ACS , & for TAN & ATN . You can use this to test how
accurately the computer works out these functions.
3.
radians are 180°, so to convert from degrees to radians you divide by 180 & multiply by
PRINT TAN (45/180* PI )
gives tan 45° (1).
To get from radians to degrees, you divide by
4. Try
PRINT RND
a few times to see how the answer varies. Can you detect any pattern? (Unlikely.)
& multiply by 180.
: thus

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents