home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / BIGNUM.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  46 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* BIGNUM.H
  4. **
  5. ** Header file with definition of BigNum type for Big Number Arithmetic.
  6. **
  7. ** Released to the public domain by Clifford Rhodes on June 15, 1995 with
  8. ** no guarantees of any sort as to accuracy or fitness of use.
  9. */
  10.  
  11. /* Each int in the Big Number array will hold a digit up to MODULUS - 1.
  12. ** Choosing 10000 makes testing easy because each digit contains 4 decimal
  13. ** places.
  14. */
  15.  
  16. #ifndef BIGNUM__H
  17. #define BIGNUM__H
  18.  
  19. #include "minmax.h"
  20.  
  21. #define MODULUS  10000    /* Warning: Must be <= USHRT_MAX! */
  22.  
  23. typedef unsigned short UShort;
  24. typedef unsigned long  ULong;
  25.  
  26. /* The Big Number is contained in a structure that has a length, nlen, and
  27. ** an array, n[], of unsigned shorts to hold the 'digits'. The most
  28. ** significant digit of the big number is at n[0]. The least significant
  29. ** digit is at n[nlen - 1];
  30. */
  31.  
  32. typedef struct {
  33.       int nlen;      /* Number of int's in n */
  34.       UShort *n;     /* Array of unsigned shorts to hold the number */
  35. } BigNum;
  36.  
  37. /* Arithmetic function prototypes */
  38. BigNum * BigNumAdd(const BigNum *a, const BigNum *b);
  39. BigNum * BigNumSub(const BigNum *a, const BigNum *b);
  40. BigNum * BigNumMul(const BigNum *a, const BigNum *b);
  41. BigNum * BigNumDiv(const BigNum *a, const BigNum *b, BigNum **c);
  42. BigNum * BigNumAlloc(int nlen);
  43. void     BigNumFree(BigNum *b);
  44.  
  45. #endif /* BIGNUM__H */
  46.