2 // minimal double precision unsigned int arithmetics for numeric_facets support.
3 // Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000
8 class _compound_int : public _Tp {
10 typedef _compound_int<_Tp> _Self;
12 // Constructors, destructor, assignment operator.
13 _compound_int(); // platform specific
14 _compound_int(unsigned long); // platform specific
15 _compound_int(unsigned long hi, unsigned long lo); // platform specific
16 _compound_int(const _Tp& rhs) : _Tp(rhs) {}
18 // Arithmetic op= operations involving two _compound_int.
19 _Self& operator+= (const _Self&); // platform specific
20 _Self& operator-= (const _Self&); // platform specific
21 _Self& operator*= (const _Self&); // platform specific
22 _Self& operator/= (const _Self&); // platform specific
23 _Self& operator%= (const _Self&); // platform specific
24 _Self& operator&= (const _Self&); // platform specific
25 _Self& operator|= (const _Self&); // platform specific
26 _Self& operator^= (const _Self&); // platform specific
28 // Arithmetic op= operations involving built-in integer.
29 _Self& operator<<= (unsigned int); // platform specific
30 _Self& operator>>= (unsigned int); // platform specific
32 _Self& operator= (unsigned long rhs) { return *this = _Self(rhs); }
33 _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
34 _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
35 _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
36 _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); }
37 _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); }
38 _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); }
39 _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); }
40 _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); }
42 // Increment and decrement
43 _Self& operator++() { return (*this) += 1; }
44 _Self& operator--() { return (*this) -= 1; }
45 _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
46 _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
49 // Comparison operators.
50 template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific
51 template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific
53 template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
54 template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
56 template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
57 template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
59 template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
60 template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
62 template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
63 template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
65 template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
66 template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
68 template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
69 template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
71 // Unary non-member arithmetic operators.
72 template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&); // platform specific
73 template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&); // platform specific
75 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
76 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
77 template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
79 // Non-member arithmetic operations involving two _compound_int arguments
81 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
82 { _compound_int<_Tp> temp(lhs); return temp += rhs; }
84 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
85 { _compound_int<_Tp> temp(lhs); return temp -= rhs; }
87 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
88 { _compound_int<_Tp> temp(lhs); return temp *= rhs; }
90 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
91 { _compound_int<_Tp> temp(lhs); return temp /= rhs; }
93 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
94 { _compound_int<_Tp> temp(lhs); return temp %= rhs; }
96 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
97 { _compound_int<_Tp> temp(lhs); return temp &= rhs; }
99 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
100 { _compound_int<_Tp> temp(lhs); return temp |= rhs; }
102 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
103 { _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
105 // Non-member arithmetic operations involving one built-in integer argument.
107 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
109 inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
112 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
114 inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
117 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
119 inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
122 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
124 inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
127 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
129 inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
132 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
134 inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
137 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
139 inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
142 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
144 inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
147 inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
149 inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
151 // platform specific specializations
152 #if defined (__MRC__) || defined (__SC__)
157 # undef modff //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
160 _STLP_BEGIN_NAMESPACE
163 typedef UInt64 uint64;
164 # define ULL(x) (U64SetU(x))
167 // Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type.
168 // Instead, it comes with external support library and struct data type representing 64bit int:
170 // struct UnsignedWide {
175 typedef _compound_int<UnsignedWide> uint64;
176 # define ULL(x) uint64(x)
177 # define ULL2(hi,lo) {hi,lo}
179 // Constructors, destructor, assignment operator.
180 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
181 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
182 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
184 // Arithmetic op= operations involving two _compound_int.
186 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs)
187 { *this = U64Add( *this, rhs ); return *this; }
189 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs)
190 { *this = U64Subtract( *this, rhs ); return *this; }
192 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs)
193 { *this = U64Multiply( *this, rhs ); return *this; }
195 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs)
196 { *this = U64Divide( *this, rhs, NULL ); return *this; }
198 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs)
199 { U64Divide( *this, rhs, this ); return *this; }
201 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs)
202 { *this = U64BitwiseAnd( *this, rhs ); return *this; }
204 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs)
205 { *this = U64BitwiseOr( *this, rhs ); return *this; }
207 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs)
208 { *this = U64BitwiseEor( *this, rhs ); return *this; }
210 // Arithmetic op= operations involving built-in integer.
212 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs)
213 { *this = U64ShiftLeft( *this, rhs ); return *this; }
215 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs)
216 { *this = U64ShiftRight( *this, rhs ); return *this; }
218 // Comparison operators.
220 inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
221 { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
223 inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
224 { return U64Compare( lhs, rhs ) < 0; }
226 inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs)
227 { return (lhs.hi == 0) && (lhs.lo == rhs); }
229 // Unary non-member arithmetic operators.
231 inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
233 inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
235 inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
237 # endif // TYPE_LONGLONG