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 >
Text File  |  1984-09-14  |  11KB  |  331 lines

  1.                   MATH EXTENDED PRECISION SUBROUTINES                                                                                                                                                                                                          
  2.  
  3.  
  4.  
  5.               Copyright 1984 Three Ring Publishing Company
  6.                              P.O.  BOX 2633
  7.                             Dublin, Ca 94568
  8.  
  9.  
  10.  
  11. These  routines were developed under the concept of CHEAPWARE;  that is,
  12. a donation would be appreciated if you find them useful but only a  very
  13. small one of $2.
  14.  
  15.  
  16.                                 SOAPBOX
  17.  
  18. The  large  discrepancy  between my source code price and my object code
  19. price (see the fee schedule below) is similar to the difference  in  the
  20. price of a single copy of a paperback book and the price of an exclusive
  21. copyright for the same book.  Popular software off the shelf in a  store
  22. ought  to  sell  for  $5  to $25, just as most books sell in that range;
  23. while special purpose software (e.g.  compilers) will command  a  higher
  24. price, just as do special purpose books (e.g.  legal references).
  25.  
  26.  
  27.                           PRODUCT DESCRIPTION
  28.  
  29. This package contains a set of subroutines and a  demonstration  program
  30. that  perform  64  bit  integer arithmetic for users of IBM PASCAL.  The
  31. subroutines are supplied only in object module format, with  the  source
  32. orderable  for  an  appropriate  fee.   Since version 1.0 and 2.0 object
  33. modules are not compatible, both have been supplied.  Should you  desire
  34. a  precision  other  than  64 bits (2**63 - 1) that can be ordered for a
  35. small fee.  While any precision the compiler and  run  time  environment
  36. can  support  is  theoretically  possible,  for  all practical purposes,
  37. operations on numbers as large as 256 bits would probably take  an  hour
  38. or more.
  39.  
  40.  
  41.                               FEE SCHEDULE
  42.  
  43. Object Module Suggested Contribution ........................ $     2.00
  44. Special Order Precision .....................................      25.00
  45. Source Code License (single copy) ...........................   2,000.00
  46. Source Code Sole Ownership ..................................  10,000.00
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.        Author:  Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
  58.  
  59.                                   1
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                   MATH EXTENDED PRECISION SUBROUTINES                                                                                                                                                                                                          
  68.  
  69.                             DISK OF CONTENTS                                                                                                                                                                                                                   
  70.  
  71.  
  72.  
  73.  
  74. FILE NAME      DESCRIPTION
  75. -----------    ---------------------------------------------------------
  76.  
  77. MATH.DOC       This documentation file for the MATH subroutine library.
  78.  
  79. MATH.INT       PASCAL interface for the MATH subroutine library.
  80.  
  81. MATH.OBJ       PASCAL v2.0 object module of MATH subroutine library.
  82.  
  83. MATHV1.OBJ     PASCAL v1.0 object module of MATH subroutine library.
  84.  
  85. MATHTEST.EXE   PASCAL v2.0 executable version of the combined MATH
  86.                subroutine library and MATHTEST driver program.
  87.  
  88. MATHTEST.PAS   PASCAL driver program that demonstrates how to use the
  89.                subroutine library.
  90.  
  91. ------------------------------------------------------------------------
  92.  
  93.  
  94.  
  95.  
  96.                     PRINTING THIS DOCUMENTATION FILE
  97.  
  98.  
  99. This  file  may  be  printed  unmodified  on  printers  that support the
  100. standard ASCII character set.
  101.  
  102.  
  103. If  this  disk is in drive B, then just use the DOS copy command to copy
  104. this file to the printer.
  105.  
  106.                        Ex:  A>copy b:math.doc prn
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.        Author:  Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
  124.  
  125.                                   2
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.                   MATH EXTENDED PRECISION SUBROUTINES                                                                                                                                                                                                          
  134.  
  135.                                 OVERVIEW                                                                                                                                                                                                                       
  136.  
  137.  
  138. The math extended precision subroutine library is comprised of a package
  139. of  procedures  and functions to allow you to do basic math to a greater
  140. degree of precision than supported by the IBM  PASCAL  compiler.   These
  141. routines  are  written in IBM PASCAL and support 64 bit arithmetic (app.
  142. +/- 9,223,000,000,000,000,000).  They support all 18 digit integers  and
  143. most 19 digit integers.
  144.  
  145.  
  146. The  algorithm  chosen is the one used at the lowest level of a computer
  147. circuit.  The advantage of using this technique, is that  the  algorithm
  148. is   already  proven,  and  the  only  exposure  for  error  is  in  the
  149. implementation.  But since hardware is being simulated in software,  the
  150. performance leaves something to be desired.
  151.  
  152.  
  153. This  set of subroutines is also an example of the concept of "package",
  154. so widely praised in the new ADA programming language.   It  is  obvious
  155. that  the  implementers of the IBM PASCAL compiler are very cognizant of
  156. the latest software engineering techniques, and have implemented one  of
  157. the  most  important in their compiler.  In the `TO USE' section of this
  158. document, you will see how they have implemented this feature.
  159.  
  160.  
  161. There are seven routines for performing math operations.
  162.  
  163.      x_add   -  add two extended precision numbers
  164.      x_comp  -  compare two extended precision numbers
  165.      x_ctox  -  convert from character to extended precision
  166.      x_div   -  divide two extended precision numbers
  167.      x_mult  -  multiply two extended precision numbers
  168.      x_sub   -  subtract two extended precision numbers
  169.      x_xtoc  -  convert from extended precision to character
  170.  
  171.  
  172. Three new types are supplied.
  173.  
  174.      xint        -  is the extended precision internal type.  It is used
  175.                     for all calculations.
  176.      xchar       -  is the character string that is the source or target
  177.                     for the conversion procedures.
  178.      xcomp_type  -  is the result of the extended precision compare.
  179.  
  180. One constant is also defined.
  181.  
  182.      xprecision  -  determines the precision of the subroutine package.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.        Author:  Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
  190.  
  191.                                   3
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.                   MATH EXTENDED PRECISION SUBROUTINES                                                                                                                                                                                                          
  200.  
  201.                           -----  TO USE  -----                                                                                                                                                                                                                 
  202.  
  203.  
  204.  
  205. The best example of how to use the package is to  see  the  sample  test
  206. program  (MATHTEST.PAS).   However,  the following instructions separate
  207. out the  pieces  for  those  of  you  not  familiar  with  IBM  PASCAL's
  208. `interface' and `implementation'.
  209.  
  210.  
  211. MATH.INT - interface
  212.  
  213. This  file contains the standard definition of all the components of the
  214. subroutine package.  You include this  in  your  program  by  using  the
  215. $include metacommand.
  216.  
  217. Example:  {$include:  'A:MATH.INT'}
  218.           program YOUR_PROGRAM (input, output);
  219.           uses MATH;
  220.  
  221.  
  222. This  same  file  was `included' in the subroutine package, so it is not
  223. possible to get out of sync without trying.
  224.  
  225.  
  226. You should notice, the interface contains a statement called  a  `unit'.
  227. This statement has a label of `math'.  By saying that your program `uses
  228. math', you make all of the components listed  on  the  `unit'  statement
  229. available to your program.  You now have access to all the components in
  230. this package you might find useful, and to none of the  components  that
  231. would   allow   you  to  damage  the  package,  either  accidentally  or
  232. deliberately.  As you can readily see, this concept is a significant aid
  233. for the production of reliable programs.
  234.  
  235.  
  236. You  may  now  reference  all  the  components of the unit as if you had
  237. written them as part of  your  program.   The  following  is  a  trivial
  238. program  (that  has  not  been compiled or tested, so it may have syntax
  239. errors), which  illustrates  the  enclosed  MATH  `interface'  and  MATH
  240. subroutine package.
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.        Author:  Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
  256.  
  257.                                   4
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.                   MATH EXTENDED PRECISION SUBROUTINES                                                                                                                                                                                                          
  266.  
  267.                       -----  SAMPLE PROGRAM  -----                                                                                                                                                                                                             
  268.  
  269.  
  270.      "A program to add two numbers read from the terminal"
  271.  
  272.  
  273. {$include: 'A:MATH.INT'}
  274.  
  275. program ADD (input, output);
  276.  
  277. uses MATH;
  278.  
  279. var  a,b,c:           XCHAR;
  280.      xa,xb,xc:        XINT;
  281.      overflow:        boolean;
  282.  
  283. begin
  284.  
  285.      readln (input, a);
  286.      readln (input, b);
  287.  
  288.      X_XTOC (a, xa, overflow);
  289.  
  290.      if overflow = true  then begin
  291.         writeln ('value a - out of range');
  292.         return
  293.         end;
  294.  
  295.      X_XTOC (b, xb, overflow);
  296.  
  297.      if overflow = true  then begin
  298.         writeln ('value b - out of range');
  299.         return
  300.         end;
  301.  
  302.      X_ADD (xa, xb, xc, overflow);
  303.  
  304.      if overflow = true  then begin
  305.         writeln ('sum of a + b out of range');
  306.         return
  307.         end;
  308.  
  309.      X_XTOC (xc, c);
  310.  
  311.      writeln (a, ' + ', b, ' = ', c);
  312.  
  313. end.
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.        Author:  Bill Ferreira, P.O. Box 2633, Dublin, CA 94568
  322.  
  323.                                   5
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.