Home » CEEFAX disks » telesoftware2.adl » OS\BITS/T\OSB20

OS\BITS/T\OSB20

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware2.adl
Filename: OS\BITS/T\OSB20
Read OK:
File size: 1D8E bytes
Load address: 0000
Exec address: 0000
Duplicates

There is 1 duplicate copy of this file in the archive:

File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

..........................................................


Part 20: Real Numbers


In this module of OSbits I am going to lead you into a
little experimentation.  We will start looking at a section
of computing mathematics that is often ignored by reference
books on the BBC micro .... real numbers.

The terminology gets a little confusing here since I have
seen different reference books give different meanings to
terms dealing with real numbers.  So here are my
definitions.

(i) An INTEGER is a number that is a whole number, in other
words its 'fractional' part is zero.  The number 1234 is an
integer.

(ii) A REAL number is a number that is not a whole number. 
It may have an integer part but it will certainly have a
fractional part.  The number 12.34 is real with an integer
part of 12 and a fractional part of .34 whereas the number
0.456 has no integer part and .456 is its fractional part.
Real numbers are sometimes called 'reals'.

(iii) Fixed point arithmetic is carried out with numbers
which all have fractional parts with the same number of
digits (for example 12.00 and 12.34 and 1.23 and 0.12 if we
have two decimal places).

(iv) Floating point arithmetic is carried out with numbers
which can have any number of digits (including none) in
their fractional part.

These definitions apply equally to numbers with any base. 
The examples above are decimal but we will eventually be
working with binary numbers following those rules.

So far all our arithmetical calculations have been done
using integers.  In these next few modules I will explore
some of the techniques for working with real numbers, first
of all in a fixed point format and then in floating point.

[Although we will not cover it in OSbits, there are methods
for dealing with true fractional quantities using a
computer.  This is where you will genuinely store a quantity
of 1/3 instead of 0.33333333 .... (and so on ad infinitum).]

With machine code we are dealing with bits in memory that
are either on or off, so there is no inherent way of storing
a fractional quantity.  A bit can not be 'half on' for
example.  This is a similar problem to negative numbers, and
so similarly a convention for representing real numbers has
to be found.

There is a convention for floating point representation in 
BBC BASIC which we will come on to in a later module, but
for fixed point we are on our own.  So what are the
considerations?  Don't forget that I will be using decimal
numbers as examples in this module.

The time taken to carry out a multiplication (for example)
depends on the number of digits in the number.  So whereas
we could say that we would store all reals simply by
multiplying by a million (so that 1.2345 became 1234500)
this has a penalty in that most numbers will have lots of
spare zeros which takes up space in memory and slows down
calculating.  The opposite side of this particular coin is
that the greater the number of digits used in such a
representation the more accurately the number is held.  This
is particularly true of fractions that do not have a finite
representation as a 'decimal', like 1/3 or 1/7 if we work in
base 10 and 1/10 if we work in base 2.

With both fixed and floating point arithmetic the trade off
is between accuracy and speed, but in this module let's say
that we are going to use a fixed point decimal format which
always gives four figures after the decimal point.

This means that, for example, 123 becomes 1230000 and
123.456 becomes 1234560.  We have introduced a factor, in
this case it is 10000, to translate our real numbers into a
fixed point format that looks like an integer.  We know that
our numbers are now in fact 10000 times too large and we can
adjust our arithmetic to allow for this.

We must have integer values in order that our machine code
arithmetic routines will work, and so we can take the
numbers multiplied up by our factor and truncated to
integers as the basis of our calculations.  In this way
0.0001234 becomes 1, since the other digits are outside the
range we have set ourselves.  It is from truncations like
this that errors are made.

Let us assume that we have two real numbers A and B and
let's see how the arithmetic now works.  Our 'real' versions
of A and B, multiplied up by our conversion factor Cfac
become Ar and Br.  The number we are looking for on the left
hand side of the equation is the result multiplied by Cfac.

Addition:

      A + B = (Ar + Br) DIV Cfac

therefore, multiplying both sides by Cfac we get

      (A + B) * Cfac = Ar + Br

Similarly for subtraction:

      (A - B) * Cfac = Ar - Br

Multiplication:

      A * B = (Ar * Br) DIV Cfac^2

therefore, multiplying both sides by Cfac we get

      (A * B) * Cfac = (Ar * Br) DIV Cfac

Division:

      A / B =  Ar DIV Br  (the conversion factor cancels)

therefore, multiplying both sides by Cfac we get

      (A / B) * Cfac =  (Ar * Cfac) DIV Br

We have to calculate (Ar * Cfac) DIV Br in the case of
division because a straight Ar DIV Br will produce an
integer answer.  We have to make sure that we have enough
space in the number for the fractional part, and multiplying
by Cfac does that.

In each case the above calculations leave a result that is
too large by the factor Cfac and we remove this factor when
we display the result (by dividing by it) just as we
included it on inputting the original numbers by multiplying
by it.

For working in binary Cfac should be byte sized, an integer
power of 256.  If your whole number is four bytes in size it
could be &100 or &10000 depending on how much fractional
accuracy you want.  In decimal it is easier to work with it
as an integer power of 10 just as here we will work using a
value of 10000 for Cfac.

So what is the point of all this fixed point stuff?  Well
basically it is simpler than floating point, where you have
to keep track of the number of 'decimal' places rather than
it being fixed.  This should speed up calculations.

The program module this week uses this fixed point principle
to carry out some simple calculations.  For simplicity Cfac
is 10000 rather than a byte value.  You can compare the
results between a 'cheap and cheerful' fixed point system
implemented using BASIC integer arithmetic and the proper
floating point maths of BASIC.  I have looped a
multiplication a thousand times so that you can get some
idea of speed.  Assume that the floating point gives the
correct answer and you will see what errors you get from the
fixed point representation.

You will see that with numbers over zero there is little
difference (a tribute to Acorn's programming) but with
smaller numbers the fixed point system becomes over twice as
fast as the floating point one.  I know that the results are
not totally accurate but I think they show that a fixed
point system can be useful where your numbers are generally
fractional.

You will also see that the difference between fixed and
floating speeds is less marked when you enter two different
sized numbers with the smaller one first.  This suggests
that as well as small numbers per se, this fixed point
routine works best when the smaller of the two numbers is
the multiplier rather than the multiplicand.

I have timed multiplying because the project for the next
module involves multiplying, but by adjusting line 160 and
280 you could test other arithmetic.  Next time I will use
fixed point arithmetic to calculate the Mandelbrot set which
is a computer graphic very heavily dependant on
multiplication.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
00000050  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00000080  2e 2e 2e 2e 0d 0d 0d 50  61 72 74 20 32 30 3a 20  |.......Part 20: |
00000090  52 65 61 6c 20 4e 75 6d  62 65 72 73 0d 0d 0d 49  |Real Numbers...I|
000000a0  6e 20 74 68 69 73 20 6d  6f 64 75 6c 65 20 6f 66  |n this module of|
000000b0  20 4f 53 62 69 74 73 20  49 20 61 6d 20 67 6f 69  | OSbits I am goi|
000000c0  6e 67 20 74 6f 20 6c 65  61 64 20 79 6f 75 20 69  |ng to lead you i|
000000d0  6e 74 6f 20 61 0d 6c 69  74 74 6c 65 20 65 78 70  |nto a.little exp|
000000e0  65 72 69 6d 65 6e 74 61  74 69 6f 6e 2e 20 20 57  |erimentation.  W|
000000f0  65 20 77 69 6c 6c 20 73  74 61 72 74 20 6c 6f 6f  |e will start loo|
00000100  6b 69 6e 67 20 61 74 20  61 20 73 65 63 74 69 6f  |king at a sectio|
00000110  6e 0d 6f 66 20 63 6f 6d  70 75 74 69 6e 67 20 6d  |n.of computing m|
00000120  61 74 68 65 6d 61 74 69  63 73 20 74 68 61 74 20  |athematics that |
00000130  69 73 20 6f 66 74 65 6e  20 69 67 6e 6f 72 65 64  |is often ignored|
00000140  20 62 79 20 72 65 66 65  72 65 6e 63 65 0d 62 6f  | by reference.bo|
00000150  6f 6b 73 20 6f 6e 20 74  68 65 20 42 42 43 20 6d  |oks on the BBC m|
00000160  69 63 72 6f 20 2e 2e 2e  2e 20 72 65 61 6c 20 6e  |icro .... real n|
00000170  75 6d 62 65 72 73 2e 0d  0d 54 68 65 20 74 65 72  |umbers...The ter|
00000180  6d 69 6e 6f 6c 6f 67 79  20 67 65 74 73 20 61 20  |minology gets a |
00000190  6c 69 74 74 6c 65 20 63  6f 6e 66 75 73 69 6e 67  |little confusing|
000001a0  20 68 65 72 65 20 73 69  6e 63 65 20 49 20 68 61  | here since I ha|
000001b0  76 65 0d 73 65 65 6e 20  64 69 66 66 65 72 65 6e  |ve.seen differen|
000001c0  74 20 72 65 66 65 72 65  6e 63 65 20 62 6f 6f 6b  |t reference book|
000001d0  73 20 67 69 76 65 20 64  69 66 66 65 72 65 6e 74  |s give different|
000001e0  20 6d 65 61 6e 69 6e 67  73 20 74 6f 0d 74 65 72  | meanings to.ter|
000001f0  6d 73 20 64 65 61 6c 69  6e 67 20 77 69 74 68 20  |ms dealing with |
00000200  72 65 61 6c 20 6e 75 6d  62 65 72 73 2e 20 20 53  |real numbers.  S|
00000210  6f 20 68 65 72 65 20 61  72 65 20 6d 79 0d 64 65  |o here are my.de|
00000220  66 69 6e 69 74 69 6f 6e  73 2e 0d 0d 28 69 29 20  |finitions...(i) |
00000230  41 6e 20 49 4e 54 45 47  45 52 20 69 73 20 61 20  |An INTEGER is a |
00000240  6e 75 6d 62 65 72 20 74  68 61 74 20 69 73 20 61  |number that is a|
00000250  20 77 68 6f 6c 65 20 6e  75 6d 62 65 72 2c 20 69  | whole number, i|
00000260  6e 20 6f 74 68 65 72 0d  77 6f 72 64 73 20 69 74  |n other.words it|
00000270  73 20 27 66 72 61 63 74  69 6f 6e 61 6c 27 20 70  |s 'fractional' p|
00000280  61 72 74 20 69 73 20 7a  65 72 6f 2e 20 20 54 68  |art is zero.  Th|
00000290  65 20 6e 75 6d 62 65 72  20 31 32 33 34 20 69 73  |e number 1234 is|
000002a0  20 61 6e 0d 69 6e 74 65  67 65 72 2e 0d 0d 28 69  | an.integer...(i|
000002b0  69 29 20 41 20 52 45 41  4c 20 6e 75 6d 62 65 72  |i) A REAL number|
000002c0  20 69 73 20 61 20 6e 75  6d 62 65 72 20 74 68 61  | is a number tha|
000002d0  74 20 69 73 20 6e 6f 74  20 61 20 77 68 6f 6c 65  |t is not a whole|
000002e0  20 6e 75 6d 62 65 72 2e  20 0d 49 74 20 6d 61 79  | number. .It may|
000002f0  20 68 61 76 65 20 61 6e  20 69 6e 74 65 67 65 72  | have an integer|
00000300  20 70 61 72 74 20 62 75  74 20 69 74 20 77 69 6c  | part but it wil|
00000310  6c 20 63 65 72 74 61 69  6e 6c 79 20 68 61 76 65  |l certainly have|
00000320  20 61 0d 66 72 61 63 74  69 6f 6e 61 6c 20 70 61  | a.fractional pa|
00000330  72 74 2e 20 20 54 68 65  20 6e 75 6d 62 65 72 20  |rt.  The number |
00000340  31 32 2e 33 34 20 69 73  20 72 65 61 6c 20 77 69  |12.34 is real wi|
00000350  74 68 20 61 6e 20 69 6e  74 65 67 65 72 0d 70 61  |th an integer.pa|
00000360  72 74 20 6f 66 20 31 32  20 61 6e 64 20 61 20 66  |rt of 12 and a f|
00000370  72 61 63 74 69 6f 6e 61  6c 20 70 61 72 74 20 6f  |ractional part o|
00000380  66 20 2e 33 34 20 77 68  65 72 65 61 73 20 74 68  |f .34 whereas th|
00000390  65 20 6e 75 6d 62 65 72  0d 30 2e 34 35 36 20 68  |e number.0.456 h|
000003a0  61 73 20 6e 6f 20 69 6e  74 65 67 65 72 20 70 61  |as no integer pa|
000003b0  72 74 20 61 6e 64 20 2e  34 35 36 20 69 73 20 69  |rt and .456 is i|
000003c0  74 73 20 66 72 61 63 74  69 6f 6e 61 6c 20 70 61  |ts fractional pa|
000003d0  72 74 2e 0d 52 65 61 6c  20 6e 75 6d 62 65 72 73  |rt..Real numbers|
000003e0  20 61 72 65 20 73 6f 6d  65 74 69 6d 65 73 20 63  | are sometimes c|
000003f0  61 6c 6c 65 64 20 27 72  65 61 6c 73 27 2e 0d 0d  |alled 'reals'...|
00000400  28 69 69 69 29 20 46 69  78 65 64 20 70 6f 69 6e  |(iii) Fixed poin|
00000410  74 20 61 72 69 74 68 6d  65 74 69 63 20 69 73 20  |t arithmetic is |
00000420  63 61 72 72 69 65 64 20  6f 75 74 20 77 69 74 68  |carried out with|
00000430  20 6e 75 6d 62 65 72 73  0d 77 68 69 63 68 20 61  | numbers.which a|
00000440  6c 6c 20 68 61 76 65 20  66 72 61 63 74 69 6f 6e  |ll have fraction|
00000450  61 6c 20 70 61 72 74 73  20 77 69 74 68 20 74 68  |al parts with th|
00000460  65 20 73 61 6d 65 20 6e  75 6d 62 65 72 20 6f 66  |e same number of|
00000470  0d 64 69 67 69 74 73 20  28 66 6f 72 20 65 78 61  |.digits (for exa|
00000480  6d 70 6c 65 20 31 32 2e  30 30 20 61 6e 64 20 31  |mple 12.00 and 1|
00000490  32 2e 33 34 20 61 6e 64  20 31 2e 32 33 20 61 6e  |2.34 and 1.23 an|
000004a0  64 20 30 2e 31 32 20 69  66 20 77 65 0d 68 61 76  |d 0.12 if we.hav|
000004b0  65 20 74 77 6f 20 64 65  63 69 6d 61 6c 20 70 6c  |e two decimal pl|
000004c0  61 63 65 73 29 2e 0d 0d  28 69 76 29 20 46 6c 6f  |aces)...(iv) Flo|
000004d0  61 74 69 6e 67 20 70 6f  69 6e 74 20 61 72 69 74  |ating point arit|
000004e0  68 6d 65 74 69 63 20 69  73 20 63 61 72 72 69 65  |hmetic is carrie|
000004f0  64 20 6f 75 74 20 77 69  74 68 20 6e 75 6d 62 65  |d out with numbe|
00000500  72 73 0d 77 68 69 63 68  20 63 61 6e 20 68 61 76  |rs.which can hav|
00000510  65 20 61 6e 79 20 6e 75  6d 62 65 72 20 6f 66 20  |e any number of |
00000520  64 69 67 69 74 73 20 28  69 6e 63 6c 75 64 69 6e  |digits (includin|
00000530  67 20 6e 6f 6e 65 29 20  69 6e 0d 74 68 65 69 72  |g none) in.their|
00000540  20 66 72 61 63 74 69 6f  6e 61 6c 20 70 61 72 74  | fractional part|
00000550  2e 0d 0d 54 68 65 73 65  20 64 65 66 69 6e 69 74  |...These definit|
00000560  69 6f 6e 73 20 61 70 70  6c 79 20 65 71 75 61 6c  |ions apply equal|
00000570  6c 79 20 74 6f 20 6e 75  6d 62 65 72 73 20 77 69  |ly to numbers wi|
00000580  74 68 20 61 6e 79 20 62  61 73 65 2e 20 0d 54 68  |th any base. .Th|
00000590  65 20 65 78 61 6d 70 6c  65 73 20 61 62 6f 76 65  |e examples above|
000005a0  20 61 72 65 20 64 65 63  69 6d 61 6c 20 62 75 74  | are decimal but|
000005b0  20 77 65 20 77 69 6c 6c  20 65 76 65 6e 74 75 61  | we will eventua|
000005c0  6c 6c 79 20 62 65 0d 77  6f 72 6b 69 6e 67 20 77  |lly be.working w|
000005d0  69 74 68 20 62 69 6e 61  72 79 20 6e 75 6d 62 65  |ith binary numbe|
000005e0  72 73 20 66 6f 6c 6c 6f  77 69 6e 67 20 74 68 6f  |rs following tho|
000005f0  73 65 20 72 75 6c 65 73  2e 0d 0d 53 6f 20 66 61  |se rules...So fa|
00000600  72 20 61 6c 6c 20 6f 75  72 20 61 72 69 74 68 6d  |r all our arithm|
00000610  65 74 69 63 61 6c 20 63  61 6c 63 75 6c 61 74 69  |etical calculati|
00000620  6f 6e 73 20 68 61 76 65  20 62 65 65 6e 20 64 6f  |ons have been do|
00000630  6e 65 0d 75 73 69 6e 67  20 69 6e 74 65 67 65 72  |ne.using integer|
00000640  73 2e 20 20 49 6e 20 74  68 65 73 65 20 6e 65 78  |s.  In these nex|
00000650  74 20 66 65 77 20 6d 6f  64 75 6c 65 73 20 49 20  |t few modules I |
00000660  77 69 6c 6c 20 65 78 70  6c 6f 72 65 0d 73 6f 6d  |will explore.som|
00000670  65 20 6f 66 20 74 68 65  20 74 65 63 68 6e 69 71  |e of the techniq|
00000680  75 65 73 20 66 6f 72 20  77 6f 72 6b 69 6e 67 20  |ues for working |
00000690  77 69 74 68 20 72 65 61  6c 20 6e 75 6d 62 65 72  |with real number|
000006a0  73 2c 20 66 69 72 73 74  0d 6f 66 20 61 6c 6c 20  |s, first.of all |
000006b0  69 6e 20 61 20 66 69 78  65 64 20 70 6f 69 6e 74  |in a fixed point|
000006c0  20 66 6f 72 6d 61 74 20  61 6e 64 20 74 68 65 6e  | format and then|
000006d0  20 69 6e 20 66 6c 6f 61  74 69 6e 67 20 70 6f 69  | in floating poi|
000006e0  6e 74 2e 0d 0d 5b 41 6c  74 68 6f 75 67 68 20 77  |nt...[Although w|
000006f0  65 20 77 69 6c 6c 20 6e  6f 74 20 63 6f 76 65 72  |e will not cover|
00000700  20 69 74 20 69 6e 20 4f  53 62 69 74 73 2c 20 74  | it in OSbits, t|
00000710  68 65 72 65 20 61 72 65  20 6d 65 74 68 6f 64 73  |here are methods|
00000720  0d 66 6f 72 20 64 65 61  6c 69 6e 67 20 77 69 74  |.for dealing wit|
00000730  68 20 74 72 75 65 20 66  72 61 63 74 69 6f 6e 61  |h true fractiona|
00000740  6c 20 71 75 61 6e 74 69  74 69 65 73 20 75 73 69  |l quantities usi|
00000750  6e 67 20 61 0d 63 6f 6d  70 75 74 65 72 2e 20 20  |ng a.computer.  |
00000760  54 68 69 73 20 69 73 20  77 68 65 72 65 20 79 6f  |This is where yo|
00000770  75 20 77 69 6c 6c 20 67  65 6e 75 69 6e 65 6c 79  |u will genuinely|
00000780  20 73 74 6f 72 65 20 61  20 71 75 61 6e 74 69 74  | store a quantit|
00000790  79 0d 6f 66 20 31 2f 33  20 69 6e 73 74 65 61 64  |y.of 1/3 instead|
000007a0  20 6f 66 20 30 2e 33 33  33 33 33 33 33 33 20 2e  | of 0.33333333 .|
000007b0  2e 2e 2e 20 28 61 6e 64  20 73 6f 20 6f 6e 20 61  |... (and so on a|
000007c0  64 20 69 6e 66 69 6e 69  74 75 6d 29 2e 5d 0d 0d  |d infinitum).]..|
000007d0  57 69 74 68 20 6d 61 63  68 69 6e 65 20 63 6f 64  |With machine cod|
000007e0  65 20 77 65 20 61 72 65  20 64 65 61 6c 69 6e 67  |e we are dealing|
000007f0  20 77 69 74 68 20 62 69  74 73 20 69 6e 20 6d 65  | with bits in me|
00000800  6d 6f 72 79 20 74 68 61  74 0d 61 72 65 20 65 69  |mory that.are ei|
00000810  74 68 65 72 20 6f 6e 20  6f 72 20 6f 66 66 2c 20  |ther on or off, |
00000820  73 6f 20 74 68 65 72 65  20 69 73 20 6e 6f 20 69  |so there is no i|
00000830  6e 68 65 72 65 6e 74 20  77 61 79 20 6f 66 20 73  |nherent way of s|
00000840  74 6f 72 69 6e 67 0d 61  20 66 72 61 63 74 69 6f  |toring.a fractio|
00000850  6e 61 6c 20 71 75 61 6e  74 69 74 79 2e 20 20 41  |nal quantity.  A|
00000860  20 62 69 74 20 63 61 6e  20 6e 6f 74 20 62 65 20  | bit can not be |
00000870  27 68 61 6c 66 20 6f 6e  27 20 66 6f 72 0d 65 78  |'half on' for.ex|
00000880  61 6d 70 6c 65 2e 20 20  54 68 69 73 20 69 73 20  |ample.  This is |
00000890  61 20 73 69 6d 69 6c 61  72 20 70 72 6f 62 6c 65  |a similar proble|
000008a0  6d 20 74 6f 20 6e 65 67  61 74 69 76 65 20 6e 75  |m to negative nu|
000008b0  6d 62 65 72 73 2c 20 61  6e 64 0d 73 6f 20 73 69  |mbers, and.so si|
000008c0  6d 69 6c 61 72 6c 79 20  61 20 63 6f 6e 76 65 6e  |milarly a conven|
000008d0  74 69 6f 6e 20 66 6f 72  20 72 65 70 72 65 73 65  |tion for represe|
000008e0  6e 74 69 6e 67 20 72 65  61 6c 20 6e 75 6d 62 65  |nting real numbe|
000008f0  72 73 20 68 61 73 0d 74  6f 20 62 65 20 66 6f 75  |rs has.to be fou|
00000900  6e 64 2e 0d 0d 54 68 65  72 65 20 69 73 20 61 20  |nd...There is a |
00000910  63 6f 6e 76 65 6e 74 69  6f 6e 20 66 6f 72 20 66  |convention for f|
00000920  6c 6f 61 74 69 6e 67 20  70 6f 69 6e 74 20 72 65  |loating point re|
00000930  70 72 65 73 65 6e 74 61  74 69 6f 6e 20 69 6e 20  |presentation in |
00000940  0d 42 42 43 20 42 41 53  49 43 20 77 68 69 63 68  |.BBC BASIC which|
00000950  20 77 65 20 77 69 6c 6c  20 63 6f 6d 65 20 6f 6e  | we will come on|
00000960  20 74 6f 20 69 6e 20 61  20 6c 61 74 65 72 20 6d  | to in a later m|
00000970  6f 64 75 6c 65 2c 20 62  75 74 0d 66 6f 72 20 66  |odule, but.for f|
00000980  69 78 65 64 20 70 6f 69  6e 74 20 77 65 20 61 72  |ixed point we ar|
00000990  65 20 6f 6e 20 6f 75 72  20 6f 77 6e 2e 20 20 53  |e on our own.  S|
000009a0  6f 20 77 68 61 74 20 61  72 65 20 74 68 65 0d 63  |o what are the.c|
000009b0  6f 6e 73 69 64 65 72 61  74 69 6f 6e 73 3f 20 20  |onsiderations?  |
000009c0  44 6f 6e 27 74 20 66 6f  72 67 65 74 20 74 68 61  |Don't forget tha|
000009d0  74 20 49 20 77 69 6c 6c  20 62 65 20 75 73 69 6e  |t I will be usin|
000009e0  67 20 64 65 63 69 6d 61  6c 0d 6e 75 6d 62 65 72  |g decimal.number|
000009f0  73 20 61 73 20 65 78 61  6d 70 6c 65 73 20 69 6e  |s as examples in|
00000a00  20 74 68 69 73 20 6d 6f  64 75 6c 65 2e 0d 0d 54  | this module...T|
00000a10  68 65 20 74 69 6d 65 20  74 61 6b 65 6e 20 74 6f  |he time taken to|
00000a20  20 63 61 72 72 79 20 6f  75 74 20 61 20 6d 75 6c  | carry out a mul|
00000a30  74 69 70 6c 69 63 61 74  69 6f 6e 20 28 66 6f 72  |tiplication (for|
00000a40  20 65 78 61 6d 70 6c 65  29 0d 64 65 70 65 6e 64  | example).depend|
00000a50  73 20 6f 6e 20 74 68 65  20 6e 75 6d 62 65 72 20  |s on the number |
00000a60  6f 66 20 64 69 67 69 74  73 20 69 6e 20 74 68 65  |of digits in the|
00000a70  20 6e 75 6d 62 65 72 2e  20 20 53 6f 20 77 68 65  | number.  So whe|
00000a80  72 65 61 73 0d 77 65 20  63 6f 75 6c 64 20 73 61  |reas.we could sa|
00000a90  79 20 74 68 61 74 20 77  65 20 77 6f 75 6c 64 20  |y that we would |
00000aa0  73 74 6f 72 65 20 61 6c  6c 20 72 65 61 6c 73 20  |store all reals |
00000ab0  73 69 6d 70 6c 79 20 62  79 0d 6d 75 6c 74 69 70  |simply by.multip|
00000ac0  6c 79 69 6e 67 20 62 79  20 61 20 6d 69 6c 6c 69  |lying by a milli|
00000ad0  6f 6e 20 28 73 6f 20 74  68 61 74 20 31 2e 32 33  |on (so that 1.23|
00000ae0  34 35 20 62 65 63 61 6d  65 20 31 32 33 34 35 30  |45 became 123450|
00000af0  30 29 0d 74 68 69 73 20  68 61 73 20 61 20 70 65  |0).this has a pe|
00000b00  6e 61 6c 74 79 20 69 6e  20 74 68 61 74 20 6d 6f  |nalty in that mo|
00000b10  73 74 20 6e 75 6d 62 65  72 73 20 77 69 6c 6c 20  |st numbers will |
00000b20  68 61 76 65 20 6c 6f 74  73 20 6f 66 0d 73 70 61  |have lots of.spa|
00000b30  72 65 20 7a 65 72 6f 73  20 77 68 69 63 68 20 74  |re zeros which t|
00000b40  61 6b 65 73 20 75 70 20  73 70 61 63 65 20 69 6e  |akes up space in|
00000b50  20 6d 65 6d 6f 72 79 20  61 6e 64 20 73 6c 6f 77  | memory and slow|
00000b60  73 20 64 6f 77 6e 0d 63  61 6c 63 75 6c 61 74 69  |s down.calculati|
00000b70  6e 67 2e 20 20 54 68 65  20 6f 70 70 6f 73 69 74  |ng.  The opposit|
00000b80  65 20 73 69 64 65 20 6f  66 20 74 68 69 73 20 70  |e side of this p|
00000b90  61 72 74 69 63 75 6c 61  72 20 63 6f 69 6e 20 69  |articular coin i|
00000ba0  73 0d 74 68 61 74 20 74  68 65 20 67 72 65 61 74  |s.that the great|
00000bb0  65 72 20 74 68 65 20 6e  75 6d 62 65 72 20 6f 66  |er the number of|
00000bc0  20 64 69 67 69 74 73 20  75 73 65 64 20 69 6e 20  | digits used in |
00000bd0  73 75 63 68 20 61 0d 72  65 70 72 65 73 65 6e 74  |such a.represent|
00000be0  61 74 69 6f 6e 20 74 68  65 20 6d 6f 72 65 20 61  |ation the more a|
00000bf0  63 63 75 72 61 74 65 6c  79 20 74 68 65 20 6e 75  |ccurately the nu|
00000c00  6d 62 65 72 20 69 73 20  68 65 6c 64 2e 20 20 54  |mber is held.  T|
00000c10  68 69 73 0d 69 73 20 70  61 72 74 69 63 75 6c 61  |his.is particula|
00000c20  72 6c 79 20 74 72 75 65  20 6f 66 20 66 72 61 63  |rly true of frac|
00000c30  74 69 6f 6e 73 20 74 68  61 74 20 64 6f 20 6e 6f  |tions that do no|
00000c40  74 20 68 61 76 65 20 61  20 66 69 6e 69 74 65 0d  |t have a finite.|
00000c50  72 65 70 72 65 73 65 6e  74 61 74 69 6f 6e 20 61  |representation a|
00000c60  73 20 61 20 27 64 65 63  69 6d 61 6c 27 2c 20 6c  |s a 'decimal', l|
00000c70  69 6b 65 20 31 2f 33 20  6f 72 20 31 2f 37 20 69  |ike 1/3 or 1/7 i|
00000c80  66 20 77 65 20 77 6f 72  6b 20 69 6e 0d 62 61 73  |f we work in.bas|
00000c90  65 20 31 30 20 61 6e 64  20 31 2f 31 30 20 69 66  |e 10 and 1/10 if|
00000ca0  20 77 65 20 77 6f 72 6b  20 69 6e 20 62 61 73 65  | we work in base|
00000cb0  20 32 2e 0d 0d 57 69 74  68 20 62 6f 74 68 20 66  | 2...With both f|
00000cc0  69 78 65 64 20 61 6e 64  20 66 6c 6f 61 74 69 6e  |ixed and floatin|
00000cd0  67 20 70 6f 69 6e 74 20  61 72 69 74 68 6d 65 74  |g point arithmet|
00000ce0  69 63 20 74 68 65 20 74  72 61 64 65 20 6f 66 66  |ic the trade off|
00000cf0  0d 69 73 20 62 65 74 77  65 65 6e 20 61 63 63 75  |.is between accu|
00000d00  72 61 63 79 20 61 6e 64  20 73 70 65 65 64 2c 20  |racy and speed, |
00000d10  62 75 74 20 69 6e 20 74  68 69 73 20 6d 6f 64 75  |but in this modu|
00000d20  6c 65 20 6c 65 74 27 73  20 73 61 79 0d 74 68 61  |le let's say.tha|
00000d30  74 20 77 65 20 61 72 65  20 67 6f 69 6e 67 20 74  |t we are going t|
00000d40  6f 20 75 73 65 20 61 20  66 69 78 65 64 20 70 6f  |o use a fixed po|
00000d50  69 6e 74 20 64 65 63 69  6d 61 6c 20 66 6f 72 6d  |int decimal form|
00000d60  61 74 20 77 68 69 63 68  0d 61 6c 77 61 79 73 20  |at which.always |
00000d70  67 69 76 65 73 20 66 6f  75 72 20 66 69 67 75 72  |gives four figur|
00000d80  65 73 20 61 66 74 65 72  20 74 68 65 20 64 65 63  |es after the dec|
00000d90  69 6d 61 6c 20 70 6f 69  6e 74 2e 0d 0d 54 68 69  |imal point...Thi|
00000da0  73 20 6d 65 61 6e 73 20  74 68 61 74 2c 20 66 6f  |s means that, fo|
00000db0  72 20 65 78 61 6d 70 6c  65 2c 20 31 32 33 20 62  |r example, 123 b|
00000dc0  65 63 6f 6d 65 73 20 31  32 33 30 30 30 30 20 61  |ecomes 1230000 a|
00000dd0  6e 64 0d 31 32 33 2e 34  35 36 20 62 65 63 6f 6d  |nd.123.456 becom|
00000de0  65 73 20 31 32 33 34 35  36 30 2e 20 20 57 65 20  |es 1234560.  We |
00000df0  68 61 76 65 20 69 6e 74  72 6f 64 75 63 65 64 20  |have introduced |
00000e00  61 20 66 61 63 74 6f 72  2c 20 69 6e 0d 74 68 69  |a factor, in.thi|
00000e10  73 20 63 61 73 65 20 69  74 20 69 73 20 31 30 30  |s case it is 100|
00000e20  30 30 2c 20 74 6f 20 74  72 61 6e 73 6c 61 74 65  |00, to translate|
00000e30  20 6f 75 72 20 72 65 61  6c 20 6e 75 6d 62 65 72  | our real number|
00000e40  73 20 69 6e 74 6f 20 61  0d 66 69 78 65 64 20 70  |s into a.fixed p|
00000e50  6f 69 6e 74 20 66 6f 72  6d 61 74 20 74 68 61 74  |oint format that|
00000e60  20 6c 6f 6f 6b 73 20 6c  69 6b 65 20 61 6e 20 69  | looks like an i|
00000e70  6e 74 65 67 65 72 2e 20  20 57 65 20 6b 6e 6f 77  |nteger.  We know|
00000e80  20 74 68 61 74 0d 6f 75  72 20 6e 75 6d 62 65 72  | that.our number|
00000e90  73 20 61 72 65 20 6e 6f  77 20 69 6e 20 66 61 63  |s are now in fac|
00000ea0  74 20 31 30 30 30 30 20  74 69 6d 65 73 20 74 6f  |t 10000 times to|
00000eb0  6f 20 6c 61 72 67 65 20  61 6e 64 20 77 65 20 63  |o large and we c|
00000ec0  61 6e 0d 61 64 6a 75 73  74 20 6f 75 72 20 61 72  |an.adjust our ar|
00000ed0  69 74 68 6d 65 74 69 63  20 74 6f 20 61 6c 6c 6f  |ithmetic to allo|
00000ee0  77 20 66 6f 72 20 74 68  69 73 2e 0d 0d 57 65 20  |w for this...We |
00000ef0  6d 75 73 74 20 68 61 76  65 20 69 6e 74 65 67 65  |must have intege|
00000f00  72 20 76 61 6c 75 65 73  20 69 6e 20 6f 72 64 65  |r values in orde|
00000f10  72 20 74 68 61 74 20 6f  75 72 20 6d 61 63 68 69  |r that our machi|
00000f20  6e 65 20 63 6f 64 65 0d  61 72 69 74 68 6d 65 74  |ne code.arithmet|
00000f30  69 63 20 72 6f 75 74 69  6e 65 73 20 77 69 6c 6c  |ic routines will|
00000f40  20 77 6f 72 6b 2c 20 61  6e 64 20 73 6f 20 77 65  | work, and so we|
00000f50  20 63 61 6e 20 74 61 6b  65 20 74 68 65 0d 6e 75  | can take the.nu|
00000f60  6d 62 65 72 73 20 6d 75  6c 74 69 70 6c 69 65 64  |mbers multiplied|
00000f70  20 75 70 20 62 79 20 6f  75 72 20 66 61 63 74 6f  | up by our facto|
00000f80  72 20 61 6e 64 20 74 72  75 6e 63 61 74 65 64 20  |r and truncated |
00000f90  74 6f 0d 69 6e 74 65 67  65 72 73 20 61 73 20 74  |to.integers as t|
00000fa0  68 65 20 62 61 73 69 73  20 6f 66 20 6f 75 72 20  |he basis of our |
00000fb0  63 61 6c 63 75 6c 61 74  69 6f 6e 73 2e 20 20 49  |calculations.  I|
00000fc0  6e 20 74 68 69 73 20 77  61 79 0d 30 2e 30 30 30  |n this way.0.000|
00000fd0  31 32 33 34 20 62 65 63  6f 6d 65 73 20 31 2c 20  |1234 becomes 1, |
00000fe0  73 69 6e 63 65 20 74 68  65 20 6f 74 68 65 72 20  |since the other |
00000ff0  64 69 67 69 74 73 20 61  72 65 20 6f 75 74 73 69  |digits are outsi|
00001000  64 65 20 74 68 65 0d 72  61 6e 67 65 20 77 65 20  |de the.range we |
00001010  68 61 76 65 20 73 65 74  20 6f 75 72 73 65 6c 76  |have set ourselv|
00001020  65 73 2e 20 20 49 74 20  69 73 20 66 72 6f 6d 20  |es.  It is from |
00001030  74 72 75 6e 63 61 74 69  6f 6e 73 20 6c 69 6b 65  |truncations like|
00001040  0d 74 68 69 73 20 74 68  61 74 20 65 72 72 6f 72  |.this that error|
00001050  73 20 61 72 65 20 6d 61  64 65 2e 0d 0d 4c 65 74  |s are made...Let|
00001060  20 75 73 20 61 73 73 75  6d 65 20 74 68 61 74 20  | us assume that |
00001070  77 65 20 68 61 76 65 20  74 77 6f 20 72 65 61 6c  |we have two real|
00001080  20 6e 75 6d 62 65 72 73  20 41 20 61 6e 64 20 42  | numbers A and B|
00001090  20 61 6e 64 0d 6c 65 74  27 73 20 73 65 65 20 68  | and.let's see h|
000010a0  6f 77 20 74 68 65 20 61  72 69 74 68 6d 65 74 69  |ow the arithmeti|
000010b0  63 20 6e 6f 77 20 77 6f  72 6b 73 2e 20 20 4f 75  |c now works.  Ou|
000010c0  72 20 27 72 65 61 6c 27  20 76 65 72 73 69 6f 6e  |r 'real' version|
000010d0  73 0d 6f 66 20 41 20 61  6e 64 20 42 2c 20 6d 75  |s.of A and B, mu|
000010e0  6c 74 69 70 6c 69 65 64  20 75 70 20 62 79 20 6f  |ltiplied up by o|
000010f0  75 72 20 63 6f 6e 76 65  72 73 69 6f 6e 20 66 61  |ur conversion fa|
00001100  63 74 6f 72 20 43 66 61  63 0d 62 65 63 6f 6d 65  |ctor Cfac.become|
00001110  20 41 72 20 61 6e 64 20  42 72 2e 20 20 54 68 65  | Ar and Br.  The|
00001120  20 6e 75 6d 62 65 72 20  77 65 20 61 72 65 20 6c  | number we are l|
00001130  6f 6f 6b 69 6e 67 20 66  6f 72 20 6f 6e 20 74 68  |ooking for on th|
00001140  65 20 6c 65 66 74 0d 68  61 6e 64 20 73 69 64 65  |e left.hand side|
00001150  20 6f 66 20 74 68 65 20  65 71 75 61 74 69 6f 6e  | of the equation|
00001160  20 69 73 20 74 68 65 20  72 65 73 75 6c 74 20 6d  | is the result m|
00001170  75 6c 74 69 70 6c 69 65  64 20 62 79 20 43 66 61  |ultiplied by Cfa|
00001180  63 2e 0d 0d 41 64 64 69  74 69 6f 6e 3a 0d 0d 20  |c...Addition:.. |
00001190  20 20 20 20 20 41 20 2b  20 42 20 3d 20 28 41 72  |     A + B = (Ar|
000011a0  20 2b 20 42 72 29 20 44  49 56 20 43 66 61 63 0d  | + Br) DIV Cfac.|
000011b0  0d 74 68 65 72 65 66 6f  72 65 2c 20 6d 75 6c 74  |.therefore, mult|
000011c0  69 70 6c 79 69 6e 67 20  62 6f 74 68 20 73 69 64  |iplying both sid|
000011d0  65 73 20 62 79 20 43 66  61 63 20 77 65 20 67 65  |es by Cfac we ge|
000011e0  74 0d 0d 20 20 20 20 20  20 28 41 20 2b 20 42 29  |t..      (A + B)|
000011f0  20 2a 20 43 66 61 63 20  3d 20 41 72 20 2b 20 42  | * Cfac = Ar + B|
00001200  72 0d 0d 53 69 6d 69 6c  61 72 6c 79 20 66 6f 72  |r..Similarly for|
00001210  20 73 75 62 74 72 61 63  74 69 6f 6e 3a 0d 0d 20  | subtraction:.. |
00001220  20 20 20 20 20 28 41 20  2d 20 42 29 20 2a 20 43  |     (A - B) * C|
00001230  66 61 63 20 3d 20 41 72  20 2d 20 42 72 0d 0d 4d  |fac = Ar - Br..M|
00001240  75 6c 74 69 70 6c 69 63  61 74 69 6f 6e 3a 0d 0d  |ultiplication:..|
00001250  20 20 20 20 20 20 41 20  2a 20 42 20 3d 20 28 41  |      A * B = (A|
00001260  72 20 2a 20 42 72 29 20  44 49 56 20 43 66 61 63  |r * Br) DIV Cfac|
00001270  5e 32 0d 0d 74 68 65 72  65 66 6f 72 65 2c 20 6d  |^2..therefore, m|
00001280  75 6c 74 69 70 6c 79 69  6e 67 20 62 6f 74 68 20  |ultiplying both |
00001290  73 69 64 65 73 20 62 79  20 43 66 61 63 20 77 65  |sides by Cfac we|
000012a0  20 67 65 74 0d 0d 20 20  20 20 20 20 28 41 20 2a  | get..      (A *|
000012b0  20 42 29 20 2a 20 43 66  61 63 20 3d 20 28 41 72  | B) * Cfac = (Ar|
000012c0  20 2a 20 42 72 29 20 44  49 56 20 43 66 61 63 0d  | * Br) DIV Cfac.|
000012d0  0d 44 69 76 69 73 69 6f  6e 3a 0d 0d 20 20 20 20  |.Division:..    |
000012e0  20 20 41 20 2f 20 42 20  3d 20 20 41 72 20 44 49  |  A / B =  Ar DI|
000012f0  56 20 42 72 20 20 28 74  68 65 20 63 6f 6e 76 65  |V Br  (the conve|
00001300  72 73 69 6f 6e 20 66 61  63 74 6f 72 20 63 61 6e  |rsion factor can|
00001310  63 65 6c 73 29 0d 0d 74  68 65 72 65 66 6f 72 65  |cels)..therefore|
00001320  2c 20 6d 75 6c 74 69 70  6c 79 69 6e 67 20 62 6f  |, multiplying bo|
00001330  74 68 20 73 69 64 65 73  20 62 79 20 43 66 61 63  |th sides by Cfac|
00001340  20 77 65 20 67 65 74 0d  0d 20 20 20 20 20 20 28  | we get..      (|
00001350  41 20 2f 20 42 29 20 2a  20 43 66 61 63 20 3d 20  |A / B) * Cfac = |
00001360  20 28 41 72 20 2a 20 43  66 61 63 29 20 44 49 56  | (Ar * Cfac) DIV|
00001370  20 42 72 0d 0d 57 65 20  68 61 76 65 20 74 6f 20  | Br..We have to |
00001380  63 61 6c 63 75 6c 61 74  65 20 28 41 72 20 2a 20  |calculate (Ar * |
00001390  43 66 61 63 29 20 44 49  56 20 42 72 20 69 6e 20  |Cfac) DIV Br in |
000013a0  74 68 65 20 63 61 73 65  20 6f 66 0d 64 69 76 69  |the case of.divi|
000013b0  73 69 6f 6e 20 62 65 63  61 75 73 65 20 61 20 73  |sion because a s|
000013c0  74 72 61 69 67 68 74 20  41 72 20 44 49 56 20 42  |traight Ar DIV B|
000013d0  72 20 77 69 6c 6c 20 70  72 6f 64 75 63 65 20 61  |r will produce a|
000013e0  6e 0d 69 6e 74 65 67 65  72 20 61 6e 73 77 65 72  |n.integer answer|
000013f0  2e 20 20 57 65 20 68 61  76 65 20 74 6f 20 6d 61  |.  We have to ma|
00001400  6b 65 20 73 75 72 65 20  74 68 61 74 20 77 65 20  |ke sure that we |
00001410  68 61 76 65 20 65 6e 6f  75 67 68 0d 73 70 61 63  |have enough.spac|
00001420  65 20 69 6e 20 74 68 65  20 6e 75 6d 62 65 72 20  |e in the number |
00001430  66 6f 72 20 74 68 65 20  66 72 61 63 74 69 6f 6e  |for the fraction|
00001440  61 6c 20 70 61 72 74 2c  20 61 6e 64 20 6d 75 6c  |al part, and mul|
00001450  74 69 70 6c 79 69 6e 67  0d 62 79 20 43 66 61 63  |tiplying.by Cfac|
00001460  20 64 6f 65 73 20 74 68  61 74 2e 0d 0d 49 6e 20  | does that...In |
00001470  65 61 63 68 20 63 61 73  65 20 74 68 65 20 61 62  |each case the ab|
00001480  6f 76 65 20 63 61 6c 63  75 6c 61 74 69 6f 6e 73  |ove calculations|
00001490  20 6c 65 61 76 65 20 61  20 72 65 73 75 6c 74 20  | leave a result |
000014a0  74 68 61 74 20 69 73 0d  74 6f 6f 20 6c 61 72 67  |that is.too larg|
000014b0  65 20 62 79 20 74 68 65  20 66 61 63 74 6f 72 20  |e by the factor |
000014c0  43 66 61 63 20 61 6e 64  20 77 65 20 72 65 6d 6f  |Cfac and we remo|
000014d0  76 65 20 74 68 69 73 20  66 61 63 74 6f 72 20 77  |ve this factor w|
000014e0  68 65 6e 0d 77 65 20 64  69 73 70 6c 61 79 20 74  |hen.we display t|
000014f0  68 65 20 72 65 73 75 6c  74 20 28 62 79 20 64 69  |he result (by di|
00001500  76 69 64 69 6e 67 20 62  79 20 69 74 29 20 6a 75  |viding by it) ju|
00001510  73 74 20 61 73 20 77 65  0d 69 6e 63 6c 75 64 65  |st as we.include|
00001520  64 20 69 74 20 6f 6e 20  69 6e 70 75 74 74 69 6e  |d it on inputtin|
00001530  67 20 74 68 65 20 6f 72  69 67 69 6e 61 6c 20 6e  |g the original n|
00001540  75 6d 62 65 72 73 20 62  79 20 6d 75 6c 74 69 70  |umbers by multip|
00001550  6c 79 69 6e 67 0d 62 79  20 69 74 2e 0d 0d 46 6f  |lying.by it...Fo|
00001560  72 20 77 6f 72 6b 69 6e  67 20 69 6e 20 62 69 6e  |r working in bin|
00001570  61 72 79 20 43 66 61 63  20 73 68 6f 75 6c 64 20  |ary Cfac should |
00001580  62 65 20 62 79 74 65 20  73 69 7a 65 64 2c 20 61  |be byte sized, a|
00001590  6e 20 69 6e 74 65 67 65  72 0d 70 6f 77 65 72 20  |n integer.power |
000015a0  6f 66 20 32 35 36 2e 20  20 49 66 20 79 6f 75 72  |of 256.  If your|
000015b0  20 77 68 6f 6c 65 20 6e  75 6d 62 65 72 20 69 73  | whole number is|
000015c0  20 66 6f 75 72 20 62 79  74 65 73 20 69 6e 20 73  | four bytes in s|
000015d0  69 7a 65 20 69 74 0d 63  6f 75 6c 64 20 62 65 20  |ize it.could be |
000015e0  26 31 30 30 20 6f 72 20  26 31 30 30 30 30 20 64  |&100 or &10000 d|
000015f0  65 70 65 6e 64 69 6e 67  20 6f 6e 20 68 6f 77 20  |epending on how |
00001600  6d 75 63 68 20 66 72 61  63 74 69 6f 6e 61 6c 0d  |much fractional.|
00001610  61 63 63 75 72 61 63 79  20 79 6f 75 20 77 61 6e  |accuracy you wan|
00001620  74 2e 20 20 49 6e 20 64  65 63 69 6d 61 6c 20 69  |t.  In decimal i|
00001630  74 20 69 73 20 65 61 73  69 65 72 20 74 6f 20 77  |t is easier to w|
00001640  6f 72 6b 20 77 69 74 68  20 69 74 0d 61 73 20 61  |ork with it.as a|
00001650  6e 20 69 6e 74 65 67 65  72 20 70 6f 77 65 72 20  |n integer power |
00001660  6f 66 20 31 30 20 6a 75  73 74 20 61 73 20 68 65  |of 10 just as he|
00001670  72 65 20 77 65 20 77 69  6c 6c 20 77 6f 72 6b 20  |re we will work |
00001680  75 73 69 6e 67 20 61 0d  76 61 6c 75 65 20 6f 66  |using a.value of|
00001690  20 31 30 30 30 30 20 66  6f 72 20 43 66 61 63 2e  | 10000 for Cfac.|
000016a0  0d 0d 53 6f 20 77 68 61  74 20 69 73 20 74 68 65  |..So what is the|
000016b0  20 70 6f 69 6e 74 20 6f  66 20 61 6c 6c 20 74 68  | point of all th|
000016c0  69 73 20 66 69 78 65 64  20 70 6f 69 6e 74 20 73  |is fixed point s|
000016d0  74 75 66 66 3f 20 20 57  65 6c 6c 0d 62 61 73 69  |tuff?  Well.basi|
000016e0  63 61 6c 6c 79 20 69 74  20 69 73 20 73 69 6d 70  |cally it is simp|
000016f0  6c 65 72 20 74 68 61 6e  20 66 6c 6f 61 74 69 6e  |ler than floatin|
00001700  67 20 70 6f 69 6e 74 2c  20 77 68 65 72 65 20 79  |g point, where y|
00001710  6f 75 20 68 61 76 65 0d  74 6f 20 6b 65 65 70 20  |ou have.to keep |
00001720  74 72 61 63 6b 20 6f 66  20 74 68 65 20 6e 75 6d  |track of the num|
00001730  62 65 72 20 6f 66 20 27  64 65 63 69 6d 61 6c 27  |ber of 'decimal'|
00001740  20 70 6c 61 63 65 73 20  72 61 74 68 65 72 20 74  | places rather t|
00001750  68 61 6e 0d 69 74 20 62  65 69 6e 67 20 66 69 78  |han.it being fix|
00001760  65 64 2e 20 20 54 68 69  73 20 73 68 6f 75 6c 64  |ed.  This should|
00001770  20 73 70 65 65 64 20 75  70 20 63 61 6c 63 75 6c  | speed up calcul|
00001780  61 74 69 6f 6e 73 2e 0d  0d 54 68 65 20 70 72 6f  |ations...The pro|
00001790  67 72 61 6d 20 6d 6f 64  75 6c 65 20 74 68 69 73  |gram module this|
000017a0  20 77 65 65 6b 20 75 73  65 73 20 74 68 69 73 20  | week uses this |
000017b0  66 69 78 65 64 20 70 6f  69 6e 74 20 70 72 69 6e  |fixed point prin|
000017c0  63 69 70 6c 65 0d 74 6f  20 63 61 72 72 79 20 6f  |ciple.to carry o|
000017d0  75 74 20 73 6f 6d 65 20  73 69 6d 70 6c 65 20 63  |ut some simple c|
000017e0  61 6c 63 75 6c 61 74 69  6f 6e 73 2e 20 20 46 6f  |alculations.  Fo|
000017f0  72 20 73 69 6d 70 6c 69  63 69 74 79 20 43 66 61  |r simplicity Cfa|
00001800  63 0d 69 73 20 31 30 30  30 30 20 72 61 74 68 65  |c.is 10000 rathe|
00001810  72 20 74 68 61 6e 20 61  20 62 79 74 65 20 76 61  |r than a byte va|
00001820  6c 75 65 2e 20 20 59 6f  75 20 63 61 6e 20 63 6f  |lue.  You can co|
00001830  6d 70 61 72 65 20 74 68  65 0d 72 65 73 75 6c 74  |mpare the.result|
00001840  73 20 62 65 74 77 65 65  6e 20 61 20 27 63 68 65  |s between a 'che|
00001850  61 70 20 61 6e 64 20 63  68 65 65 72 66 75 6c 27  |ap and cheerful'|
00001860  20 66 69 78 65 64 20 70  6f 69 6e 74 20 73 79 73  | fixed point sys|
00001870  74 65 6d 0d 69 6d 70 6c  65 6d 65 6e 74 65 64 20  |tem.implemented |
00001880  75 73 69 6e 67 20 42 41  53 49 43 20 69 6e 74 65  |using BASIC inte|
00001890  67 65 72 20 61 72 69 74  68 6d 65 74 69 63 20 61  |ger arithmetic a|
000018a0  6e 64 20 74 68 65 20 70  72 6f 70 65 72 0d 66 6c  |nd the proper.fl|
000018b0  6f 61 74 69 6e 67 20 70  6f 69 6e 74 20 6d 61 74  |oating point mat|
000018c0  68 73 20 6f 66 20 42 41  53 49 43 2e 20 20 49 20  |hs of BASIC.  I |
000018d0  68 61 76 65 20 6c 6f 6f  70 65 64 20 61 0d 6d 75  |have looped a.mu|
000018e0  6c 74 69 70 6c 69 63 61  74 69 6f 6e 20 61 20 74  |ltiplication a t|
000018f0  68 6f 75 73 61 6e 64 20  74 69 6d 65 73 20 73 6f  |housand times so|
00001900  20 74 68 61 74 20 79 6f  75 20 63 61 6e 20 67 65  | that you can ge|
00001910  74 20 73 6f 6d 65 0d 69  64 65 61 20 6f 66 20 73  |t some.idea of s|
00001920  70 65 65 64 2e 20 20 41  73 73 75 6d 65 20 74 68  |peed.  Assume th|
00001930  61 74 20 74 68 65 20 66  6c 6f 61 74 69 6e 67 20  |at the floating |
00001940  70 6f 69 6e 74 20 67 69  76 65 73 20 74 68 65 0d  |point gives the.|
00001950  63 6f 72 72 65 63 74 20  61 6e 73 77 65 72 20 61  |correct answer a|
00001960  6e 64 20 79 6f 75 20 77  69 6c 6c 20 73 65 65 20  |nd you will see |
00001970  77 68 61 74 20 65 72 72  6f 72 73 20 79 6f 75 20  |what errors you |
00001980  67 65 74 20 66 72 6f 6d  20 74 68 65 0d 66 69 78  |get from the.fix|
00001990  65 64 20 70 6f 69 6e 74  20 72 65 70 72 65 73 65  |ed point represe|
000019a0  6e 74 61 74 69 6f 6e 2e  0d 0d 59 6f 75 20 77 69  |ntation...You wi|
000019b0  6c 6c 20 73 65 65 20 74  68 61 74 20 77 69 74 68  |ll see that with|
000019c0  20 6e 75 6d 62 65 72 73  20 6f 76 65 72 20 7a 65  | numbers over ze|
000019d0  72 6f 20 74 68 65 72 65  20 69 73 20 6c 69 74 74  |ro there is litt|
000019e0  6c 65 0d 64 69 66 66 65  72 65 6e 63 65 20 28 61  |le.difference (a|
000019f0  20 74 72 69 62 75 74 65  20 74 6f 20 41 63 6f 72  | tribute to Acor|
00001a00  6e 27 73 20 70 72 6f 67  72 61 6d 6d 69 6e 67 29  |n's programming)|
00001a10  20 62 75 74 20 77 69 74  68 0d 73 6d 61 6c 6c 65  | but with.smalle|
00001a20  72 20 6e 75 6d 62 65 72  73 20 74 68 65 20 66 69  |r numbers the fi|
00001a30  78 65 64 20 70 6f 69 6e  74 20 73 79 73 74 65 6d  |xed point system|
00001a40  20 62 65 63 6f 6d 65 73  20 6f 76 65 72 20 74 77  | becomes over tw|
00001a50  69 63 65 20 61 73 0d 66  61 73 74 20 61 73 20 74  |ice as.fast as t|
00001a60  68 65 20 66 6c 6f 61 74  69 6e 67 20 70 6f 69 6e  |he floating poin|
00001a70  74 20 6f 6e 65 2e 20 20  49 20 6b 6e 6f 77 20 74  |t one.  I know t|
00001a80  68 61 74 20 74 68 65 20  72 65 73 75 6c 74 73 20  |hat the results |
00001a90  61 72 65 0d 6e 6f 74 20  74 6f 74 61 6c 6c 79 20  |are.not totally |
00001aa0  61 63 63 75 72 61 74 65  20 62 75 74 20 49 20 74  |accurate but I t|
00001ab0  68 69 6e 6b 20 74 68 65  79 20 73 68 6f 77 20 74  |hink they show t|
00001ac0  68 61 74 20 61 20 66 69  78 65 64 0d 70 6f 69 6e  |hat a fixed.poin|
00001ad0  74 20 73 79 73 74 65 6d  20 63 61 6e 20 62 65 20  |t system can be |
00001ae0  75 73 65 66 75 6c 20 77  68 65 72 65 20 79 6f 75  |useful where you|
00001af0  72 20 6e 75 6d 62 65 72  73 20 61 72 65 20 67 65  |r numbers are ge|
00001b00  6e 65 72 61 6c 6c 79 0d  66 72 61 63 74 69 6f 6e  |nerally.fraction|
00001b10  61 6c 2e 0d 0d 59 6f 75  20 77 69 6c 6c 20 61 6c  |al...You will al|
00001b20  73 6f 20 73 65 65 20 74  68 61 74 20 74 68 65 20  |so see that the |
00001b30  64 69 66 66 65 72 65 6e  63 65 20 62 65 74 77 65  |difference betwe|
00001b40  65 6e 20 66 69 78 65 64  20 61 6e 64 0d 66 6c 6f  |en fixed and.flo|
00001b50  61 74 69 6e 67 20 73 70  65 65 64 73 20 69 73 20  |ating speeds is |
00001b60  6c 65 73 73 20 6d 61 72  6b 65 64 20 77 68 65 6e  |less marked when|
00001b70  20 79 6f 75 20 65 6e 74  65 72 20 74 77 6f 20 64  | you enter two d|
00001b80  69 66 66 65 72 65 6e 74  0d 73 69 7a 65 64 20 6e  |ifferent.sized n|
00001b90  75 6d 62 65 72 73 20 77  69 74 68 20 74 68 65 20  |umbers with the |
00001ba0  73 6d 61 6c 6c 65 72 20  6f 6e 65 20 66 69 72 73  |smaller one firs|
00001bb0  74 2e 20 20 54 68 69 73  20 73 75 67 67 65 73 74  |t.  This suggest|
00001bc0  73 0d 74 68 61 74 20 61  73 20 77 65 6c 6c 20 61  |s.that as well a|
00001bd0  73 20 73 6d 61 6c 6c 20  6e 75 6d 62 65 72 73 20  |s small numbers |
00001be0  70 65 72 20 73 65 2c 20  74 68 69 73 20 66 69 78  |per se, this fix|
00001bf0  65 64 20 70 6f 69 6e 74  0d 72 6f 75 74 69 6e 65  |ed point.routine|
00001c00  20 77 6f 72 6b 73 20 62  65 73 74 20 77 68 65 6e  | works best when|
00001c10  20 74 68 65 20 73 6d 61  6c 6c 65 72 20 6f 66 20  | the smaller of |
00001c20  74 68 65 20 74 77 6f 20  6e 75 6d 62 65 72 73 20  |the two numbers |
00001c30  69 73 0d 74 68 65 20 6d  75 6c 74 69 70 6c 69 65  |is.the multiplie|
00001c40  72 20 72 61 74 68 65 72  20 74 68 61 6e 20 74 68  |r rather than th|
00001c50  65 20 6d 75 6c 74 69 70  6c 69 63 61 6e 64 2e 0d  |e multiplicand..|
00001c60  0d 49 20 68 61 76 65 20  74 69 6d 65 64 20 6d 75  |.I have timed mu|
00001c70  6c 74 69 70 6c 79 69 6e  67 20 62 65 63 61 75 73  |ltiplying becaus|
00001c80  65 20 74 68 65 20 70 72  6f 6a 65 63 74 20 66 6f  |e the project fo|
00001c90  72 20 74 68 65 20 6e 65  78 74 0d 6d 6f 64 75 6c  |r the next.modul|
00001ca0  65 20 69 6e 76 6f 6c 76  65 73 20 6d 75 6c 74 69  |e involves multi|
00001cb0  70 6c 79 69 6e 67 2c 20  62 75 74 20 62 79 20 61  |plying, but by a|
00001cc0  64 6a 75 73 74 69 6e 67  20 6c 69 6e 65 20 31 36  |djusting line 16|
00001cd0  30 20 61 6e 64 0d 32 38  30 20 79 6f 75 20 63 6f  |0 and.280 you co|
00001ce0  75 6c 64 20 74 65 73 74  20 6f 74 68 65 72 20 61  |uld test other a|
00001cf0  72 69 74 68 6d 65 74 69  63 2e 20 20 4e 65 78 74  |rithmetic.  Next|
00001d00  20 74 69 6d 65 20 49 20  77 69 6c 6c 20 75 73 65  | time I will use|
00001d10  0d 66 69 78 65 64 20 70  6f 69 6e 74 20 61 72 69  |.fixed point ari|
00001d20  74 68 6d 65 74 69 63 20  74 6f 20 63 61 6c 63 75  |thmetic to calcu|
00001d30  6c 61 74 65 20 74 68 65  20 4d 61 6e 64 65 6c 62  |late the Mandelb|
00001d40  72 6f 74 20 73 65 74 20  77 68 69 63 68 0d 69 73  |rot set which.is|
00001d50  20 61 20 63 6f 6d 70 75  74 65 72 20 67 72 61 70  | a computer grap|
00001d60  68 69 63 20 76 65 72 79  20 68 65 61 76 69 6c 79  |hic very heavily|
00001d70  20 64 65 70 65 6e 64 61  6e 74 20 6f 6e 0d 6d 75  | dependant on.mu|
00001d80  6c 74 69 70 6c 69 63 61  74 69 6f 6e 2e 0d        |ltiplication..|
00001d8e
OS\BITS/T\OSB20.m0
OS\BITS/T\OSB20.m1
OS\BITS/T\OSB20.m2
OS\BITS/T\OSB20.m4
OS\BITS/T\OSB20.m5