home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bcdclass.zip / BCD.H next >
Text File  |  1995-09-24  |  2KB  |  51 lines

  1. // bcd.h  Binary Coded Decimal Class ****************  W. D. Connors 7/29/95
  2. typedef unsigned short USHORT;
  3. class bcd
  4. {
  5. private:
  6.    char intgl[16];       // yields 32 digits of precision
  7.    char sign;            // char sign
  8.    int condcode;         // indicator for underflow, overflow, divide by zero
  9.  
  10. // private methods
  11.  
  12. int decAdd(char * rslt, const char * src, int digofs, int bytofs, int swap, int sub);
  13. int sigd(char * igl, int expn);
  14. bcd opadd(const bcd & a, const bcd & b, char tsign);
  15. bcd opdiv(const bcd & a, const bcd & b, char ret);
  16. int opshr(bcd & a, USHORT sa);
  17. int opcmp(const bcd & a, const bcd & b);
  18.  
  19. public:
  20.    bcd(void);                          // default constructor - initialize to zero
  21.    bcd(const bcd & b);                 // construct from another bcd
  22.    bcd(const char * sz);               // constructor from numeric string
  23.    bcd(const double x);                // constructor from floating point number
  24.    bcd(const long num);                // constructor from long integer
  25.    bcd(char * rslt, char sg, int cc);  // constructor from discreet pieces
  26.    ~bcd();                             // destructor
  27.  
  28. // public methods
  29.    int bcdToString(char * st, USHORT dp = 0); // str returned w/decimal point at dp
  30.    int rcc();             // returns condition code from bcd structure
  31.    int shr(USHORT decdg);    // shift right decdg decimal digits
  32.    int shrRnd(USHORT decdg); // shift right decdg decimal digits and round
  33.    int shrCpld(bcd & dest, USHORT decdg); // shift decdg digits into dest (lo order)
  34.    int shl(USHORT decdg);    // shift left decdg decimal digits
  35.    int sigD();  // returns the number of significant digits - quick bcd zero test
  36.  
  37. // operator overloading
  38.    bcd operator=(const bcd & b);    // assignment
  39.    bcd operator+(const bcd & b);    // addition
  40.    bcd operator-(const bcd & b);    // subtraction
  41.    bcd operator-(void);             // unary negator
  42.    bcd operator*(const bcd & b);    // multiplication
  43.    bcd operator/(const bcd & b);    // division
  44.    bcd operator%(const bcd & b);    // modulus
  45.    int operator<(const bcd & b);    // logical ops
  46.    int operator>(const bcd & b);    // et cetera
  47.    int operator==(const bcd & b);
  48.    int operator!=(const bcd & b);
  49.    friend ostream & operator<<(ostream & os, const bcd &b);
  50. };
  51.