home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_09 / 1109078a < prev    next >
Text File  |  1993-04-10  |  3KB  |  127 lines

  1. /*----------------------------------------------------
  2.  
  3.       Module: FIXED.H
  4.       
  5.       Class: Fixed
  6.       
  7.       Description: 
  8.       
  9.       
  10.       Revision History
  11. -----------------------------------------------------
  12.   Date      Name  Comment
  13. -----------------------------------------------------
  14.  
  15. Feb-16-93   rbf   Added the addProduct function
  16.  
  17. Nov-24-92   rbf   Initial Creation
  18.  
  19. ---------------------------------------------------*/
  20.  
  21. #ifndef      _FIXED_H
  22. #define      _FIXED_H
  23.  
  24. #if !defined(__IOSTREAM_H)
  25. #include <iostream.h>
  26. #endif
  27.  
  28. typedef signed long FixedData;
  29.  
  30. // construct a union of a Fixed
  31. // and two int sized parts
  32. // for easy access to the appropriate bits
  33.  
  34. typedef union
  35.    {
  36.    FixedData long_rep;
  37.    struct
  38.       {
  39.       unsigned int   fractional_part;
  40.         signed int   whole_part;
  41.       } half_rep;
  42.    } FixedUnion;
  43.  
  44.  
  45. // Definition of class Fixed
  46. // in the Orthodox Canonical Form
  47.  
  48. class   Fixed
  49.    {
  50.  
  51.    public:  // Public interface to class
  52.       
  53.       // Boilerplate member functions
  54.       
  55.       // default constructor
  56.       Fixed();
  57.       
  58.       // default copy constructor
  59.       inline Fixed(const Fixed&);
  60.       
  61.       // default assignment
  62.       inline Fixed& operator=(const Fixed&);
  63.       
  64.       // default destructor
  65.       ~Fixed();
  66.       
  67.       // Class specific member functions & data
  68.  
  69.       friend ostream& operator<<
  70.          ( ostream& s, Fixed& rhs );
  71.  
  72.       // various constructors & conversion operators
  73.       // construct a Fixed from an int
  74.       Fixed(int rhs);
  75.       // construct a Fixed from an double or float
  76.       Fixed(double rhs);   
  77.  
  78.  
  79.       // binary operators on a Fixed class
  80.  
  81.       friend   Fixed operator-
  82.          (const Fixed& lhs, const Fixed& rhs);
  83.       friend   Fixed operator+
  84.          (const Fixed& lhs, const Fixed& rhs);
  85.       friend   Fixed operator*
  86.          (const Fixed& lhs, const Fixed& rhs);
  87.       friend   Fixed   operator/
  88.          (const Fixed& lhs, const Fixed& rhs);
  89.       friend   int   operator<
  90.          (const Fixed& lhs, const Fixed& rhs);
  91.       friend   int   operator>
  92.          (const Fixed& lhs, const Fixed& rhs);
  93.       friend   int   operator==
  94.          (const Fixed& lhs, const Fixed& rhs);
  95.       friend   int   operator!=
  96.          (const Fixed& lhs, const Fixed& rhs);
  97.       friend   int   operator<=
  98.          (const Fixed& lhs, const Fixed& rhs);
  99.       friend   int   operator>=
  100.          (const Fixed& lhs, const Fixed& rhs);
  101.  
  102.       // unary operators on a Fixed class
  103.       inline   Fixed&   operator+=(const Fixed& rhs);
  104.       inline   Fixed&   operator-=(const Fixed& rhs);
  105.       inline   Fixed&   operator*=(const Fixed& rhs);
  106.       inline   Fixed&   operator/=(const Fixed& rhs);
  107.       inline   Fixed      operator+ ();
  108.       inline   Fixed      operator- ();
  109.  
  110.       void      addProduct(const Fixed& rhs1,const Fixed& rhs2);
  111.  
  112.    protected:  // Protected interface to class
  113.       
  114.       // Protected member functions & data
  115.       
  116.       
  117.    private:  // Private interface to class
  118.       
  119.       // Private member functions & data
  120.       FixedUnion fixeddata;
  121.  
  122.  
  123.    };   // Fixed
  124.  
  125.  
  126. #endif      _FIXED_H
  127.