home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 105_01 / long.doc < prev    next >
Text File  |  1984-06-05  |  4KB  |  109 lines

  1.                    LONG INTEGERS
  2.  
  3.               (c) 1981 by Paul J. Gans
  4.  
  5.  
  6.  
  7. The Long Integer Package
  8.  
  9.      The Long Integer Package is a collection of functions
  10. designed to provide the users of Leor Zolman's BDS C with
  11. the ability to manipulate long integers.  This package has
  12. been modeled upon the Floating Point Package for BDS C
  13. written by Bob Mathias and works in a similar manner.
  14.  
  15.      The package works with long integers stored as four
  16. consecutive bytes with the least significant byte stored
  17. at the lowest memory address.  The precision maintained is
  18. 31 bits plus sign.  To use the package, all long integers
  19. should be declared as four byte char arrays.  Manipulation
  20. is by pointer to the arrays.  Thus the code
  21.  
  22.         char first[4], second[4], result[4];
  23.  
  24. could define three long integers.
  25.  
  26.      The possible range a long integer longform may
  27. occupy is:
  28.  
  29.           -2147483648 <= longform <= 2147483647
  30.  
  31.  
  32.      Long integers are manipulated via the following
  33. functions:
  34.  
  35.    char *ladd(sum,addend,augend)
  36.    char sum[4], addend[4], augend[4];
  37.       adds addend and augend, stores the 32 bit signed
  38.       result in sum and returns a pointer to sum.
  39.  
  40.    char *lsub(diff,minuend,subtrahend)
  41.    char diff[4], minuend[4], subtrahend[4];
  42.       subtracts subtrahend from minuend and places the
  43.       32 bit signed result in diff.  A pointer to diff
  44.       is returned.
  45.  
  46.    char *lmul(prod,plier,plicand)
  47.    char prod[4], plier[4], plicand[4];
  48.       plier and plicand are multiplied.  The least
  49.       signficant 31 bits of the product along with the
  50.       appropriate sign bit are stored in prod.  A pointer
  51.       to prod is returned.
  52.  
  53.    char *ldiv(quot,dividend,divisior)
  54.    char quot[4], dividend[4], divisor[4];
  55.       dividend is divided by divisor.  The least
  56.       significant 31 bits of the quotient along with the
  57.       proper sign are stored in quot.  A pointer to prod
  58.       is produced.  Note that no indication of overflow
  59.       is produced should it occur.
  60.  
  61.    char *lmod(res,dividend,divisor)
  62.    char res[4], dividend[4], divisor[4];
  63.       dividend is divided by divisor.  The positive 31
  64.       bit remainder is placed in res and a pointer to it
  65.       is returned.
  66.  
  67.    char *lneg(newnum,orignum)
  68.    char newnum[4], orignum[4];
  69.       orignum is negated and placed in newnum.  A pointer
  70.       to newnum is returned.
  71.  
  72.    char *itol(longform,i)
  73.    char longform[4];
  74.    int  i;
  75.       i is converted to long integer form and placed in
  76.       longform to which a pointer is returned.
  77.  
  78.    int ltoi(i,longform)
  79.    char longform[4];
  80.    int  i;
  81.       the low order 15 bits of longform along with the
  82.       proper sign are placed in i, which value is returned.
  83.  
  84.    char *atol(longform,s)
  85.    char longform[4], *s;
  86.       the '\0' terminated ASCII string s is converted to
  87.       a long integer and stored in longform to which a
  88.       pointer is returned.  The proper format for s is:
  89.       any amount of white space followed by an optional
  90.       sign followed by decimal digits.  The first non-
  91.       digit terminates the scan.  No check is made for
  92.       overflow and improper results will result if too
  93.       many decimal digits are presented.
  94.  
  95.    char *ltoa(s,longform)
  96.    char longform[4], *s;
  97.       the long integer longform is converted to a '\0'
  98.       terminated ASCII string prefixed by a minus sign
  99.       if longform is negative.  The string is placed in
  100.       s to which a pointer is returned.  Note that the
  101.       maximum length s may attain is 12, counting 10
  102.       numerical digits, a possible minus sign, and the
  103.       terminating '\0'.
  104.  
  105.  
  106.      The Long Integer Package was written by Paul J. Gans,
  107. Department of Chemistry, New York University, New York,
  108. NY  10003.  Phone (212) 598-2515.  Bug reports welcomed.
  109. d retu