1 //////////////////////////////////////////////////////////////////////////////
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
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
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef binary_coded_decimal_h
26 #define binary_coded_decimal_h
29 #include <AD/generic/generic.h>
31 ///////////////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////////////
42 // Constructor and destructor
43 ////////////////////////////////////////////////////////////////////////
45 BCD(long); // e.g. BCD n = 1234;
46 BCD(const BCD
&); // e.g. BCD n = m;
49 ////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////
52 operator const char * () const { return digits
; }
54 ////////////////////////////////////////////////////////////////////////
56 ////////////////////////////////////////////////////////////////////////
57 BCD
& operator = (long);
58 BCD
& operator = (const BCD
&);
60 ////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////
63 char operator [] (int i
) const { return digits
[i
+1]; }
65 ////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////////////////
87 friend ostream
& operator << (ostream
&, const BCD
&);
88 friend istream
& operator >> (istream
&, BCD
&);