initial
[prop.git] / include / AD / numeric / bcd.h
blobe9984f3bafa68bb45f9aca5f9ac47b2bc27338bf
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef binary_coded_decimal_h
26 #define binary_coded_decimal_h
28 #include <iostream.h>
29 #include <AD/generic/generic.h>
31 ///////////////////////////////////////////////////////////////////////////
32 // Class BCD
33 ///////////////////////////////////////////////////////////////////////////
35 class BCD {
37 char * digits;
39 public:
41 ////////////////////////////////////////////////////////////////////////
42 // Constructor and destructor
43 ////////////////////////////////////////////////////////////////////////
44 BCD(); // e.g. BCD n;
45 BCD(long); // e.g. BCD n = 1234;
46 BCD(const BCD&); // e.g. BCD n = m;
47 ~BCD();
49 ////////////////////////////////////////////////////////////////////////
50 // Conversion
51 ////////////////////////////////////////////////////////////////////////
52 operator const char * () const { return digits; }
54 ////////////////////////////////////////////////////////////////////////
55 // Assignment
56 ////////////////////////////////////////////////////////////////////////
57 BCD& operator = (long);
58 BCD& operator = (const BCD&);
60 ////////////////////////////////////////////////////////////////////////
61 // Selectors
62 ////////////////////////////////////////////////////////////////////////
63 char operator [] (int i) const { return digits[i+1]; }
65 ////////////////////////////////////////////////////////////////////////
66 // Arithmetic
67 ////////////////////////////////////////////////////////////////////////
68 BCD operator - ();
69 friend BCD operator + (const BCD&, const BCD&);
70 friend BCD operator - (const BCD&, const BCD&);
71 friend BCD operator * (const BCD&, const BCD&);
72 friend BCD operator / (const BCD&, const BCD&);
74 ////////////////////////////////////////////////////////////////////////
75 // Comparison
76 ////////////////////////////////////////////////////////////////////////
77 friend Bool operator == (const BCD&, const BCD&);
78 friend Bool operator != (const BCD&, const BCD&);
79 friend Bool operator > (const BCD&, const BCD&);
80 friend Bool operator < (const BCD&, const BCD&);
81 friend Bool operator >= (const BCD&, const BCD&);
82 friend Bool operator <= (const BCD&, const BCD&);
84 ////////////////////////////////////////////////////////////////////////
85 // I/O
86 ////////////////////////////////////////////////////////////////////////
87 friend ostream& operator << (ostream&, const BCD&);
88 friend istream& operator >> (istream&, BCD&);
91 #endif