HiSoft Pascal Primer cover: a square, a triangle and a circle drawn and filled by a HiSoft Pascal program on the Tatung Einstein
← Back to Courses
module
6

Numbers

Introduction

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.

A Space After Every Integer

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.

Hexadecimal

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.

When A Sum Goes Too Far

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:

SumWhat happens
Two variables added or subtracted past the rangeOverflow at PC=...
Any multiplication past the rangeOverflow at PC=...
A variable plus or minus a constant - I:=I+1wraps 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).

Reals

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.

Rounding

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)
Turbo3-3
HiSoft3-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.

The Maths Functions

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

The Code

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.

Change One Thing

  • Change line 120 to I:=I+1; WRITELN(I). The same sum - what happens now?
  • Put it back, and add 5 (*$O-*). What does line 120 print?
  • Change line 40's 7:3 to 7:1. Where does the space go?

Exercises

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.

When It Goes Wrong

SymptomCause
Numbers in a sentence have a gap after themEvery 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 errorIt passed 32767 by adding a constant, which is not checked.
*ERROR* 10 at a big numberNumbers past 32767 are reals, and cannot go into an INTEGER.
*ERROR* 12 after DIVA minus sign straight after DIV or MOD. Bracket it.
*ERROR* 3 at SIN or COSCompile with ;T.
ROUND is one out on a negative halfIt takes halves upwards: ROUND(-2.5) is -2.

Summary

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.

Next

S7, Names - where HiSoft Pascal is stricter than Turbo, and where it is looser.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.