ZX 81 - BASIC Programming

Sinclair ZX Spectrum
Chapter 4.2 - The Sinclair ZX81 as a calculator

Exercises

1. Try

PRINT 2.34E0

PRINT 2.34E1

PRINT 2.34E2

and so on up to

PRINT 2.34E15

You will see that after a while the ZX81 also starts using scientific notation. This is because it never takes more than 14 spaces to write a number in. Similarly, try

PRINT 2.34E-1

PRINT 2.34E-2

& so on.

2. Try

PRINT 1,,2,,3,,,4,,,,5

A comma always moves you on a bit for the next number. Now try

PRINT 1;;2;;3;;;4;;;;5

Why is a string of semicolons no different from a single one?

3. PRINT gives only 8 significant digits. Try

PRINT 4294967295, 4294967295 -429E7

This proves that the computer can hold all the digits of 4294967295, even though it is not prepared to display them all at once.

4. If you've got some log tables, then test out this rule:

Raising 10 to the power of a number is the same as taking the antilog of that number. For instance, type

PRINT 10**0.3010

& look up the antilog of 0.3010. Why are the answers not exactly equal?

5. The ZX81 uses floating point arithmetic, which means that it keeps separate the digits of a number (its mantissa) and the position of the point (the exponent). This is not always exact, even for whole numbers. Type

PRINT 1E10+1-1E10,1E10-1E10+1

Numbers are held to about 9 1/2 digits accuracy, so 1E10 is too big to be held exactly right. The inaccuracy (actually about 2) is more than 1, so the numbers 1E10 & 1E10+1 appear to the computer to be equal.

For an even more peculiar example, type

PRINT 5E9+1-5E9

Here the inaccuracy in 5E9 is only about 1, & the 1 to be added on in fact gets rounded up to 2. Here the numbers 5E9+1 & 5E9+2 appear to the computer to be equal.

The larger integer (whole number) that can be held completely accurately is 232-1 (4,294,967,295).

Sinclair ZX Spectrum

  Previous Page Back Next Page