
A computer that could only print what you typed would not be worth the electricity. This section is the other half of PRINT: everything outside quotation marks, which BASIC works out before it shows you.
Most of it will go exactly as you expect. Two things will not, and they are both worth ten minutes now rather than an afternoon later.
+ - | add, subtract |
* / | multiply, divide |
^ | raise to a power - 2^10 is 1024 |
MOD | the remainder - 7 MOD 3 is 1 |
MOD is a word but it goes between its two numbers, like the symbols: 7 MOD 3, not MOD(7,3).
Division always gives a fraction. PRINT 10/4 is 2.5, not 2. If you want the whole number, ask for it: INT(10/4) is 2.
PRINT 2+3*4 gives 14, not 20: the multiplication happens first. The full order, strongest first:
^* / MOD+ -Brackets beat all of it, and are never wrong to add: PRINT (2+3)*4 gives 20.
One to know about: -2^2 is -4, not 4. The power is taken first and the minus applied to the answer.
This is where BASIC differs from a calculator, and the rules are worth knowing because every number your programs print will follow them.
There is a space in front. PRINT 5 gives 5, with a leading space where the minus sign would go. A negative number has the minus there instead. So a column of numbers lines up.
Six digits, and no more. PRINT 1/3 gives .333333 - six significant digits, rounded, and no 0 before the point. PRINT 10/3 gives 3.33333. This is not how accurately BASIC works; it is how much it shows.
Very big and very small numbers switch to E notation. Anything from .01 to 999999 is written out in full. Outside that you get the mantissa, E, and a signed two-digit exponent:
PRINT 2^30
1.07374E+09
PRINT .001
1E-03
1E-03 means 1 divided by 1000. 1.07374E+09 means 1.07374 times a thousand million.
An E-notation number followed by + or - is misread.
PRINT 1E3+5
1E+35
That should be 1005. BASIC has read the +5 as part of the exponent and given you 1 times 10 to the 35th. Put the sum in brackets, or write the number as 1000, and all is well. It is a real fault in this BASIC, it is silent, and you would never guess it from the answer.
MOD goes wrong on very large numbers. Above 65535 it is sometimes exactly one too small - 100000 MOD 7 gives 4 where the answer is 5 - with no warning. Below that nothing has been seen to fail. If you need a remainder of a big number, work it out yourself:
10 A=100000
20 B=7
30 PRINT A-INT(A/B)*B
which gives the right answer for any size.
Whole numbers are exact up to 16777216. Past that, counting by ones stops working. The largest number at all is about 1.70141E+38.
Fractions are held to about six or seven digits, which is enough that 1/3*3 comes back as exactly 1 and .1+.2 is exactly .3. Do not lean on that too hard - SQR(2)*SQR(2) is not exactly 2 - but for a game's arithmetic it is comfortable.
10 PRINT 2+3*4
20 PRINT (2+3)*4
30 PRINT 10/4
40 PRINT 2^10
50 PRINT 7 MOD 3
60 PRINT 1/3
70 PRINT 2^30
Starting from
Anything; nothing is remembered from before.
What you should see
RUN
14
20
2.5
1024
1
.333333
1.07374E+09
Ready

Every leading space is a real space. Look at how .333333 has no zero in front of the point.
PRINT -2^2. What comes out, and can you say why before you run it?PRINT 100*100*100. A million is a round number - so why is the answer written the way it is?PRINT INT(10/4). Now try PRINT INT 10/4 without the brackets. What does the error tell you about what INT( really is?7.1 Print the area of a circle of radius 5, and then its circumference. Use 3.14159.
7.2 Convert 50 degrees Fahrenheit to Celsius - subtract 32, multiply by 5, divide by 9 - in one PRINT, using brackets to get the order right.
7.3 Print the remainder when 17 is divided by 5, and then the square root of 2. Then try the square root of -2 and read the error.
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
An answer ending E+35 or similar nonsense | An E-notation number with + or - after it. Bracket the sum or write the number in full. |
PRINT INT 10/4 gives Syntax Error | A function's brackets are part of its name. INT(10/4). |
| A remainder is one too small | MOD above 65535. Use A-INT(A/B)*B. |
Division Error | Something divided by zero - including 0^-1. |
Qty Error from SQR | The square root of a negative number. |
PRINT 1,000 prints two numbers | A comma separates two things to print; it is not a thousands separator. |
| A line printed something and then reported an error | BASIC does a statement as far as it can before it complains. |
+ - * / ^ MOD, with ^ strongest and brackets above everything. Division always gives a fraction; INT( throws it away. Numbers print with a leading space and six significant digits, in full between .01 and 999999 and in E notation outside. Watch for 1E3+5, and for MOD on big numbers.
S8, Names For Numbers - keeping a number somewhere and giving it a name, and the one trap in this BASIC that catches everybody.