uint64.h

00001 //      uint64.h
00002 //      minimal double precision unsigned int arithmetics for numeric_facets support.
00003 //      Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000
00004 
00005 #ifndef _UINT64_H
00006 #define _UINT64_H
00007 
00008 
00009 
00010 template <class _Tp>
00011 class _compound_int : public _Tp
00012 {
00013 public:
00014   typedef _compound_int<_Tp> _Self;
00015 
00016   // Constructors, destructor, assignment operator.
00017   _compound_int();                                                                              // platform specific
00018   _compound_int(unsigned long);                                                 // platform specific
00019   _compound_int(unsigned long hi, unsigned long lo);    // platform specific
00020   _compound_int(const _Tp& rhs) : _Tp(rhs) {}
00021 
00022   // Arithmetic op= operations involving two _compound_int.
00023   _Self& operator+= (const _Self&);                                             // platform specific
00024   _Self& operator-= (const _Self&);                                             // platform specific
00025   _Self& operator*= (const _Self&);                                             // platform specific
00026   _Self& operator/= (const _Self&);                                             // platform specific
00027   _Self& operator%= (const _Self&);                                             // platform specific
00028   _Self& operator&= (const _Self&);                                             // platform specific
00029   _Self& operator|= (const _Self&);                                             // platform specific
00030   _Self& operator^= (const _Self&);                                             // platform specific
00031 
00032   // Arithmetic op= operations involving built-in integer.
00033   _Self& operator<<= (unsigned int);                                    // platform specific
00034   _Self& operator>>= (unsigned int);                                    // platform specific
00035   
00036   _Self& operator=  (unsigned long rhs) { return *this =  _Self(rhs); }
00037   _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
00038   _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
00039   _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
00040   _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); }
00041   _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); }
00042   _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); }
00043   _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); }
00044   _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); }
00045 
00046   // Increment and decrement
00047   _Self& operator++() { return (*this) += 1; }
00048   _Self& operator--() { return (*this) -= 1; }
00049   _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
00050   _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
00051 };
00052 
00053 // Comparison operators.
00054 template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&);     // platform specific
00055 template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&);      // platform specific
00056 
00057 template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
00058 template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
00059 
00060 template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
00061 template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
00062 
00063 template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
00064 template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
00065 
00066 template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
00067 template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
00068 
00069 template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
00070 template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
00071 
00072 template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
00073 template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
00074 
00075 // Unary non-member arithmetic operators.
00076 template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&);                 // platform specific
00077 template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&);   // platform specific
00078 
00079 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
00080 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
00081 template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
00082 
00083 // Non-member arithmetic operations involving two _compound_int arguments
00084 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp += rhs; }
00085 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp -= rhs; }
00086 template <class _Tp> inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp *= rhs; }
00087 template <class _Tp> inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp /= rhs; }
00088 template <class _Tp> inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp %= rhs; }
00089 template <class _Tp> inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp &= rhs; }
00090 template <class _Tp> inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp |= rhs; }
00091 template <class _Tp> inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
00092 
00093 // Non-member arithmetic operations involving one built-in integer argument.
00094 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
00095 template <class _Tp> inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
00096 
00097 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
00098 template <class _Tp> inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
00099 
00100 template <class _Tp> inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
00101 template <class _Tp> inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
00102 
00103 template <class _Tp> inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
00104 template <class _Tp> inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
00105 
00106 template <class _Tp> inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
00107 template <class _Tp> inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
00108 
00109 template <class _Tp> inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
00110 template <class _Tp> inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
00111 
00112 template <class _Tp> inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
00113 template <class _Tp> inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
00114 
00115 template <class _Tp> inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
00116 template <class _Tp> inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
00117 
00118 template <class _Tp> inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
00119 template <class _Tp> inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
00120 
00121 
00122 
00123 
00124 // platform specific specializations
00125 
00126 #if defined(__MRC__)||defined(__SC__)
00127 
00128 _STLP_END_NAMESPACE // ugly!
00129 # include <Math64.h>
00130 # include <utility>
00131 # undef modff           //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
00132 # include <fp.h>
00133 
00134 _STLP_BEGIN_NAMESPACE
00135 
00136 # if TYPE_LONGLONG 
00137 typedef UInt64 uint64;
00138 # define ULL(x) (U64SetU(x))
00139 
00140 # else
00141 //      Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type. 
00142 //      Instead, it comes with external support library and struct data type representing 64bit int:
00143 //      
00144 //              struct UnsignedWide {
00145 //                      UInt32  hi;
00146 //                      UInt32  lo;
00147 //              };
00148 
00149 typedef _compound_int<UnsignedWide> uint64;
00150 # define ULL(x) uint64(x)
00151 # define ULL2(hi,lo) {hi,lo}
00152 
00153 // Constructors, destructor, assignment operator.
00154 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
00155 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
00156 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
00157 
00158 // Arithmetic op= operations involving two _compound_int.
00159 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs) { *this = U64Add( *this, rhs ); return *this; }
00160 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs) { *this = U64Subtract( *this, rhs ); return *this; }
00161 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs) { *this = U64Multiply( *this, rhs ); return *this; }
00162 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs) { *this = U64Divide( *this, rhs, NULL ); return *this; }
00163 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs) { U64Divide( *this, rhs, this ); return *this; }
00164 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseAnd( *this, rhs ); return *this; }
00165 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseOr( *this, rhs ); return *this; }
00166 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseEor( *this, rhs ); return *this; }
00167 
00168 // Arithmetic op= operations involving built-in integer.
00169 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs) { *this = U64ShiftLeft( *this, rhs ); return *this; }
00170 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs) { *this = U64ShiftRight( *this, rhs ); return *this; }
00171 
00172 // Comparison operators.
00173 _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
00174 _STLP_TEMPLATE_NULL inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) { return U64Compare( lhs, rhs ) < 0; }
00175 _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs) { return (lhs.hi == 0) && (lhs.lo == rhs); }
00176 
00177 // Unary non-member arithmetic operators.
00178 _STLP_TEMPLATE_NULL inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
00179 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
00180 _STLP_TEMPLATE_NULL inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
00181 
00182 # endif // TYPE_LONGLONG
00183 #endif // __MRC__
00184 #endif // _UINT64_H

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6