EasyManuals Logo

Sinclair QL Beginner's Guide

Sinclair QL
135 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #60 background imageLoading...
Page #60 background image
The following examples show common uses of the INT function.
100 REMark Rounding
110 INPUT decimal
120 PRINT INT(decimal + 0.5)
In the example you input a decimal fraction and the output is rounded. Thus 4.7 would become 5 but
4.3 would become 4.
You can achieve the same result using an integer variable and coercion.
Trigonometrical functions will be dealt with in a later section but other common numeric functions are
given in the list below.
Function
Effect
Examples
Returned values
ABS
Absolute or unsigned value
ABS(7)
ABS(-4.3)
7
4.3
INT
Integer part of a floating point
number
INT(2.4)
INT(0.4)
INT(-2.7)
2
0
-3
SQRT
Square root
SQRT(2)
SQRT(16)
SQRT(2.6)
1.414214
4
1.612452
There is a way of computing square roots which is easy to understand. To compute the square root of
8 first make a guess. It doesn't matter how bad the guess maybe. Suppose you simply take half of 8
as the first guess which is 4.
Because 4 is greater than the square root of 8 then 8/4 must be less than it. The reverse is also true.
If you had guessed 2 which is less than the square root then 8/2 must be greater than it.
It follows that if we take any guess and computer number/guess we have two numbers, one too small
and one too big. We take the average of these numbers as our next approximation and thus get
closer to the correct answer.
We repeat this process until successive approximations are so close as to make little difference:
100 REMark Square Roots
110 LET number = 8
120 LET approx = number/2
130 REPeat root
140 LET newval = (approx + number/approx)/2
150 IF newval == approx THE EXIT root
160 LET approx = newval
170 END REPeat root
180 PRINT 'Square root of' ! number ! 'is' ! newval
sample output:
Square root of 8 is 2.828427
Notice that the conditional EXIT from the loop must be in the middle. The traditional structures do not
cope with this situation as well as SuperBASIC does. The == sign in line 150 means "approximately
equal to", that is, equal to within .0000001 of the values being compared.

Other manuals for Sinclair QL

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair QL and is the answer not in the manual?

Sinclair QL Specifications

General IconGeneral
ProcessorMotorola 68008
Clock Speed7.5 MHz
RAM128 KB (expandable to 640 KB)
ROM48 KB
Operating SystemSinclair QDOS
Release Year1984
StorageMicrodrive tape loop
Graphics256x256 pixels, 8 colors
PortsRS-232, ROM cartridge
SoundBeeper (internal speaker)

Related product manuals