EasyManua.ls Logo

Commodore CBM - Multiplication

Commodore CBM
447 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
You now know
two
methods of subtraction. The first method used numeric
strings. The second uses multiple integer math. By comparing their outputs. vou
can
see
that both methods work equally weil
at
getting around the
9-digit
length
limit. You. the programmer. may now choose the method
which
most specifically
meets your needs.
MULTIPLICATION
The PETs
9-digit
length
limit
may
be
easily exceeded because a product
may
be
very large even when the multiplier and multiplicand are small. This
numeric length
limit
prohibits products longer than nine digits trom being printed
without
exponential notation. You can get around this limitation by
writing
a pro-
gram that
print
products larger than nine digits of precision. Printing products ex-
ceeding nine digits
without
exponential notation
is
most easily done using multi-
ple integer multiplication.
The following program
and
discussion will enable
vou
to print out products
up
to
16
digits
in
length without exponential nota·
tion.
Multiple Integer Multiplication
Using virtually the same steps
as
multiple integer addition and subtraction.
multiple integer multiplication separates the multiplicand and multiplier into
smaller segments. multiplies ail segments. and adds the multiple products
together into one final product. ranging from 1 to 16 digits in length.
The steps for multiple integer multiplication are
as
follows:
1.
Input the multiplicand and the multiplier
as
two
positive numeric
strings.
2.
Divide the strings into segments: high and low.
3.
Multiply the corresponding segments.
4.
Add the segment products to create one product string. Truncate any
leading
zeros.
5.
Print the product string.
The listing of the sample program
is
shown at the end of this section.
Step 1: Input the multiplicand
and
the multiplier
as
two
positive
numeric strings.
where
A$
is
the multiplicand and
B$
is
the multiplier. As
with
the other math programs. the numbers are input
as
strings to avoid the
9-digit
length limit. However. the input numbers are limited somewhat by the program
supplied
here.
This program Iimits the length of the product to
16
digits. Since the
maximum product length equals the sum of the lengths of the multiplicand
and
multiplier. the
sum
of the lengths of the input numbers cannot exceed
16.
To change the program to accept larger numbers requires several alterations
in the program
which
will
not
be
discussed. but
which
vou should
be
able to do
yourself.
215

Table of Contents

Other manuals for Commodore CBM

Related product manuals