home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_100
/
164_01
/
math.doc
< prev
next >
Wrap
Text File
|
1984-09-14
|
11KB
|
331 lines
MATH EXTENDED PRECISION SUBROUTINES
Copyright 1984 Three Ring Publishing Company
P.O. BOX 2633
Dublin, Ca 94568
These routines were developed under the concept of CHEAPWARE; that is,
a donation would be appreciated if you find them useful but only a very
small one of $2.
SOAPBOX
The large discrepancy between my source code price and my object code
price (see the fee schedule below) is similar to the difference in the
price of a single copy of a paperback book and the price of an exclusive
copyright for the same book. Popular software off the shelf in a store
ought to sell for $5 to $25, just as most books sell in that range;
while special purpose software (e.g. compilers) will command a higher
price, just as do special purpose books (e.g. legal references).
PRODUCT DESCRIPTION
This package contains a set of subroutines and a demonstration program
that perform 64 bit integer arithmetic for users of IBM PASCAL. The
subroutines are supplied only in object module format, with the source
orderable for an appropriate fee. Since version 1.0 and 2.0 object
modules are not compatible, both have been supplied. Should you desire
a precision other than 64 bits (2**63 - 1) that can be ordered for a
small fee. While any precision the compiler and run time environment
can support is theoretically possible, for all practical purposes,
operations on numbers as large as 256 bits would probably take an hour
or more.
FEE SCHEDULE
Object Module Suggested Contribution ........................ $ 2.00
Special Order Precision ..................................... 25.00
Source Code License (single copy) ........................... 2,000.00
Source Code Sole Ownership .................................. 10,000.00
Author: Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
1
MATH EXTENDED PRECISION SUBROUTINES
DISK OF CONTENTS
FILE NAME DESCRIPTION
----------- ---------------------------------------------------------
MATH.DOC This documentation file for the MATH subroutine library.
MATH.INT PASCAL interface for the MATH subroutine library.
MATH.OBJ PASCAL v2.0 object module of MATH subroutine library.
MATHV1.OBJ PASCAL v1.0 object module of MATH subroutine library.
MATHTEST.EXE PASCAL v2.0 executable version of the combined MATH
subroutine library and MATHTEST driver program.
MATHTEST.PAS PASCAL driver program that demonstrates how to use the
subroutine library.
------------------------------------------------------------------------
PRINTING THIS DOCUMENTATION FILE
This file may be printed unmodified on printers that support the
standard ASCII character set.
If this disk is in drive B, then just use the DOS copy command to copy
this file to the printer.
Ex: A>copy b:math.doc prn
Author: Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
2
MATH EXTENDED PRECISION SUBROUTINES
OVERVIEW
The math extended precision subroutine library is comprised of a package
of procedures and functions to allow you to do basic math to a greater
degree of precision than supported by the IBM PASCAL compiler. These
routines are written in IBM PASCAL and support 64 bit arithmetic (app.
+/- 9,223,000,000,000,000,000). They support all 18 digit integers and
most 19 digit integers.
The algorithm chosen is the one used at the lowest level of a computer
circuit. The advantage of using this technique, is that the algorithm
is already proven, and the only exposure for error is in the
implementation. But since hardware is being simulated in software, the
performance leaves something to be desired.
This set of subroutines is also an example of the concept of "package",
so widely praised in the new ADA programming language. It is obvious
that the implementers of the IBM PASCAL compiler are very cognizant of
the latest software engineering techniques, and have implemented one of
the most important in their compiler. In the `TO USE' section of this
document, you will see how they have implemented this feature.
There are seven routines for performing math operations.
x_add - add two extended precision numbers
x_comp - compare two extended precision numbers
x_ctox - convert from character to extended precision
x_div - divide two extended precision numbers
x_mult - multiply two extended precision numbers
x_sub - subtract two extended precision numbers
x_xtoc - convert from extended precision to character
Three new types are supplied.
xint - is the extended precision internal type. It is used
for all calculations.
xchar - is the character string that is the source or target
for the conversion procedures.
xcomp_type - is the result of the extended precision compare.
One constant is also defined.
xprecision - determines the precision of the subroutine package.
Author: Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
3
MATH EXTENDED PRECISION SUBROUTINES
----- TO USE -----
The best example of how to use the package is to see the sample test
program (MATHTEST.PAS). However, the following instructions separate
out the pieces for those of you not familiar with IBM PASCAL's
`interface' and `implementation'.
MATH.INT - interface
This file contains the standard definition of all the components of the
subroutine package. You include this in your program by using the
$include metacommand.
Example: {$include: 'A:MATH.INT'}
program YOUR_PROGRAM (input, output);
uses MATH;
This same file was `included' in the subroutine package, so it is not
possible to get out of sync without trying.
You should notice, the interface contains a statement called a `unit'.
This statement has a label of `math'. By saying that your program `uses
math', you make all of the components listed on the `unit' statement
available to your program. You now have access to all the components in
this package you might find useful, and to none of the components that
would allow you to damage the package, either accidentally or
deliberately. As you can readily see, this concept is a significant aid
for the production of reliable programs.
You may now reference all the components of the unit as if you had
written them as part of your program. The following is a trivial
program (that has not been compiled or tested, so it may have syntax
errors), which illustrates the enclosed MATH `interface' and MATH
subroutine package.
Author: Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
4
MATH EXTENDED PRECISION SUBROUTINES
----- SAMPLE PROGRAM -----
"A program to add two numbers read from the terminal"
{$include: 'A:MATH.INT'}
program ADD (input, output);
uses MATH;
var a,b,c: XCHAR;
xa,xb,xc: XINT;
overflow: boolean;
begin
readln (input, a);
readln (input, b);
X_XTOC (a, xa, overflow);
if overflow = true then begin
writeln ('value a - out of range');
return
end;
X_XTOC (b, xb, overflow);
if overflow = true then begin
writeln ('value b - out of range');
return
end;
X_ADD (xa, xb, xc, overflow);
if overflow = true then begin
writeln ('sum of a + b out of range');
return
end;
X_XTOC (xc, c);
writeln (a, ' + ', b, ' = ', c);
end.
Author: Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
5