
INTEGER and REAL are the same idea as in the Turbo course, and most of S7 to S9 carries straight over: DIV, MOD, :w:d, MAXINT of 32767. This section is the handful of places where the same program gives a different answer.
The first thing you will notice. Turbo wrote an integer with nothing round it; HiSoft Pascal writes a space after it:
WRITELN('[',7,']') [7 ]
WRITELN(12,34) 12 34
Handy for a list of numbers, awkward inside a sentence. A width turns it off: 7:3 gives 7, right-aligned in three columns as in Turbo, with no space after, and a width exactly the number's length - 7:1, 77:2 - gives just the digits.
Booleans and characters get no space: WRITELN(TRUE,FALSE) prints TRUEFALSE.
Two things Turbo did not have. A number can be written in hexadecimal with a third part, H: WRITELN(255:4:H) prints 00FF. And a constant can be given in hexadecimal with # in front: #FF is 255. Both come into their own in S19.
In Turbo, an integer that went past 32767 wrapped round without a word - 32767 + 1 was -32768. HiSoft Pascal stops the program - most of the time:
| Sum | What happens |
|---|---|
| Two variables added or subtracted past the range | Overflow at PC=... |
| Any multiplication past the range | Overflow at PC=... |
A variable plus or minus a constant - I:=I+1 | wraps round, no error |
The last row is worth remembering: a counter that runs up with I:=I+1 past 32767 turns negative, exactly as in Turbo, and nothing says so.
(*$O-*) turns the check off for sums: then two variables wrap round too. Multiplication is checked whatever you do.
Numbers past 32767 are reals. Written in a program, 40000 - or -32768 - is not an integer at all, and giving it to an INTEGER is error 10. (Turbo refused -32768 too.)
DIV and MOD work as in Turbo, cutting towards zero: -7 DIV 2 is -3 and -7 MOD 2 is -1. A minus sign straight after them needs brackets: 7 DIV (-2), not 7 DIV -2, which is error 12. And DIV by zero stops the program (S5).
HiSoft's reals are smaller than Turbo's: about seven significant figures, against Turbo's eleven. 2.00002-2 gives 2.00272E-05 - the last figures are gone.
They are also written differently. With no width, a real takes 12 columns (Turbo used 18): a space or minus sign, a figure, five decimals, and the exponent:
WRITELN(1/3) 3.33333E-01
WRITELN(1/3:8:4) 0.3333
:w:d works as in Turbo.
TRUNC cuts towards zero, as in Turbo. ROUND does not round as Turbo did. Turbo took a half away from zero; HiSoft Pascal takes a half upwards:
ROUND(2.5) | ROUND(-2.5) | |
|---|---|---|
| Turbo | 3 | -3 |
| HiSoft | 3 | -2 |
And there is one Turbo did not have: ENTIER, the whole number at or below: ENTIER(-2.5) is -3, where TRUNC(-2.5) is -2.
SQRT and SQR are always there. SIN, COS, TAN, ARCTAN, EXP, LN and FRAC are not, unless you ask for them on the command line with ;T (S4): without it, COS is error 3, an undeclared name. With it, the program carries the extra code - about 1,200 bytes.
HPEIN MATHS;T
10 PROGRAM NUMBERS;
20 VAR I,J:INTEGER; R:REAL;
30 BEGIN
40 WRITELN('[',7,']','[',7:3,']');
50 WRITELN(255:4:H);
60 WRITELN(-7 DIV 2,-7 MOD 2);
70 R:=1/3;
80 WRITELN(R,' ',R:8:4);
90 WRITELN(ROUND(2.5),ROUND(-2.5));
100 WRITELN(TRUNC(-2.5),ENTIER(-2.5));
110 I:=32767; J:=1;
120 WRITELN(I+J)
130 END.
Starting from
NUMBERS.ASC saved from XBAS; HPEIN NUMBERS.
What you should see
[7 ][ 7]
00FF
-3 -1
3.33333E-01 0.3333
3 -2
-2 -3
Overflow at PC=0FBA
The last line is line 120: 32767 + 1 in two variables.
I:=I+1; WRITELN(I). The same sum - what happens now?5 (*$O-*). What does line 120 print?7:3 to 7:1. Where does the space go?6.1 Print the numbers 1 to 10 and their squares in two neat columns, with no stray spaces at the ends of the lines.
6.2 Print 1000, 4096 and 32767 in hexadecimal.
6.3 Print ROUND, TRUNC and ENTIER of 3.5, -3.5 and -3.4 side by side. Which two agree for positive numbers?
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
| Numbers in a sentence have a gap after them | Every integer is written with a space after it. Give it a width. |
Overflow at PC=... | A sum or product went past 32767. |
| A count has gone negative, with no error | It passed 32767 by adding a constant, which is not checked. |
*ERROR* 10 at a big number | Numbers past 32767 are reals, and cannot go into an INTEGER. |
*ERROR* 12 after DIV | A minus sign straight after DIV or MOD. Bracket it. |
*ERROR* 3 at SIN or COS | Compile with ;T. |
ROUND is one out on a negative half | It takes halves upwards: ROUND(-2.5) is -2. |
An integer is written with a space after it unless you give a width; :H writes hexadecimal and # reads it. Sums past 32767 stop the program - except a constant added or subtracted, which wraps. Reals keep about seven figures and print in 12 columns. ROUND takes halves upwards; ENTIER rounds down; the maths functions need ;T.
S7, Names - where HiSoft Pascal is stricter than Turbo, and where it is looser.