os/ossrv/genericopenlibs/cppstdlib/stl/src/uint64.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//  uint64.h
sl@0
     2
//  minimal double precision unsigned int arithmetics for numeric_facets support.
sl@0
     3
//  Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000
sl@0
     4
#ifndef _UINT64_H
sl@0
     5
#define _UINT64_H
sl@0
     6
sl@0
     7
template <class _Tp>
sl@0
     8
class _compound_int : public _Tp {
sl@0
     9
public:
sl@0
    10
  typedef _compound_int<_Tp> _Self;
sl@0
    11
sl@0
    12
  // Constructors, destructor, assignment operator.
sl@0
    13
  _compound_int();                    // platform specific
sl@0
    14
  _compound_int(unsigned long);              // platform specific
sl@0
    15
  _compound_int(unsigned long hi, unsigned long lo);  // platform specific
sl@0
    16
  _compound_int(const _Tp& rhs) : _Tp(rhs) {}
sl@0
    17
sl@0
    18
  // Arithmetic op= operations involving two _compound_int.
sl@0
    19
  _Self& operator+= (const _Self&);            // platform specific
sl@0
    20
  _Self& operator-= (const _Self&);            // platform specific
sl@0
    21
  _Self& operator*= (const _Self&);            // platform specific
sl@0
    22
  _Self& operator/= (const _Self&);            // platform specific
sl@0
    23
  _Self& operator%= (const _Self&);            // platform specific
sl@0
    24
  _Self& operator&= (const _Self&);            // platform specific
sl@0
    25
  _Self& operator|= (const _Self&);            // platform specific
sl@0
    26
  _Self& operator^= (const _Self&);            // platform specific
sl@0
    27
sl@0
    28
  // Arithmetic op= operations involving built-in integer.
sl@0
    29
  _Self& operator<<= (unsigned int);          // platform specific
sl@0
    30
  _Self& operator>>= (unsigned int);          // platform specific
sl@0
    31
sl@0
    32
  _Self& operator=  (unsigned long rhs) { return *this =  _Self(rhs); }
sl@0
    33
  _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
sl@0
    34
  _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
sl@0
    35
  _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
sl@0
    36
  _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); }
sl@0
    37
  _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); }
sl@0
    38
  _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); }
sl@0
    39
  _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); }
sl@0
    40
  _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); }
sl@0
    41
sl@0
    42
  // Increment and decrement
sl@0
    43
  _Self& operator++() { return (*this) += 1; }
sl@0
    44
  _Self& operator--() { return (*this) -= 1; }
sl@0
    45
  _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
sl@0
    46
  _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
sl@0
    47
};
sl@0
    48
sl@0
    49
// Comparison operators.
sl@0
    50
template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
sl@0
    51
template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
sl@0
    52
sl@0
    53
template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
sl@0
    54
template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
sl@0
    55
sl@0
    56
template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
sl@0
    57
template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
sl@0
    58
sl@0
    59
template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
sl@0
    60
template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
sl@0
    61
sl@0
    62
template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
sl@0
    63
template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
sl@0
    64
sl@0
    65
template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
sl@0
    66
template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
sl@0
    67
sl@0
    68
template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
sl@0
    69
template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
sl@0
    70
sl@0
    71
// Unary non-member arithmetic operators.
sl@0
    72
template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&);      // platform specific
sl@0
    73
template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&);  // platform specific
sl@0
    74
sl@0
    75
template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
sl@0
    76
template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
sl@0
    77
template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
sl@0
    78
sl@0
    79
// Non-member arithmetic operations involving two _compound_int arguments
sl@0
    80
template <class _Tp>
sl@0
    81
inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    82
{ _compound_int<_Tp> temp(lhs); return temp += rhs; }
sl@0
    83
template <class _Tp>
sl@0
    84
inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    85
{ _compound_int<_Tp> temp(lhs); return temp -= rhs; }
sl@0
    86
template <class _Tp>
sl@0
    87
inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    88
{ _compound_int<_Tp> temp(lhs); return temp *= rhs; }
sl@0
    89
template <class _Tp>
sl@0
    90
inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    91
{ _compound_int<_Tp> temp(lhs); return temp /= rhs; }
sl@0
    92
template <class _Tp>
sl@0
    93
inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    94
{ _compound_int<_Tp> temp(lhs); return temp %= rhs; }
sl@0
    95
template <class _Tp>
sl@0
    96
inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
    97
{ _compound_int<_Tp> temp(lhs); return temp &= rhs; }
sl@0
    98
template <class _Tp>
sl@0
    99
inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
   100
{ _compound_int<_Tp> temp(lhs); return temp |= rhs; }
sl@0
   101
template <class _Tp>
sl@0
   102
inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
sl@0
   103
{ _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
sl@0
   104
sl@0
   105
// Non-member arithmetic operations involving one built-in integer argument.
sl@0
   106
template <class _Tp>
sl@0
   107
inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
sl@0
   108
template <class _Tp>
sl@0
   109
inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
sl@0
   110
sl@0
   111
template <class _Tp>
sl@0
   112
inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
sl@0
   113
template <class _Tp>
sl@0
   114
inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
sl@0
   115
sl@0
   116
template <class _Tp>
sl@0
   117
inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
sl@0
   118
template <class _Tp>
sl@0
   119
inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
sl@0
   120
sl@0
   121
template <class _Tp>
sl@0
   122
inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
sl@0
   123
template <class _Tp>
sl@0
   124
inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
sl@0
   125
sl@0
   126
template <class _Tp>
sl@0
   127
inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
sl@0
   128
template <class _Tp>
sl@0
   129
inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
sl@0
   130
sl@0
   131
template <class _Tp>
sl@0
   132
inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
sl@0
   133
template <class _Tp>
sl@0
   134
inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
sl@0
   135
sl@0
   136
template <class _Tp>
sl@0
   137
inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
sl@0
   138
template <class _Tp>
sl@0
   139
inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
sl@0
   140
sl@0
   141
template <class _Tp>
sl@0
   142
inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
sl@0
   143
template <class _Tp>
sl@0
   144
inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
sl@0
   145
sl@0
   146
template <class _Tp>
sl@0
   147
inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
sl@0
   148
template <class _Tp>
sl@0
   149
inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
sl@0
   150
sl@0
   151
// platform specific specializations
sl@0
   152
#if defined (__MRC__) || defined (__SC__)
sl@0
   153
sl@0
   154
_STLP_END_NAMESPACE
sl@0
   155
#  include <Math64.h>
sl@0
   156
#  include <utility>
sl@0
   157
#  undef modff    //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
sl@0
   158
#  include <fp.h>
sl@0
   159
sl@0
   160
_STLP_BEGIN_NAMESPACE
sl@0
   161
sl@0
   162
#  if TYPE_LONGLONG
sl@0
   163
typedef UInt64 uint64;
sl@0
   164
#    define ULL(x) (U64SetU(x))
sl@0
   165
sl@0
   166
#  else
sl@0
   167
//  Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type.
sl@0
   168
//  Instead, it comes with external support library and struct data type representing 64bit int:
sl@0
   169
//
sl@0
   170
//    struct UnsignedWide {
sl@0
   171
//      UInt32   hi;
sl@0
   172
//      UInt32   lo;
sl@0
   173
//    };
sl@0
   174
sl@0
   175
typedef _compound_int<UnsignedWide> uint64;
sl@0
   176
#    define ULL(x) uint64(x)
sl@0
   177
#    define ULL2(hi,lo) {hi,lo}
sl@0
   178
sl@0
   179
// Constructors, destructor, assignment operator.
sl@0
   180
_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
sl@0
   181
_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
sl@0
   182
_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
sl@0
   183
sl@0
   184
// Arithmetic op= operations involving two _compound_int.
sl@0
   185
_STLP_TEMPLATE_NULL
sl@0
   186
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs)
sl@0
   187
{ *this = U64Add( *this, rhs ); return *this; }
sl@0
   188
_STLP_TEMPLATE_NULL
sl@0
   189
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs)
sl@0
   190
{ *this = U64Subtract( *this, rhs ); return *this; }
sl@0
   191
_STLP_TEMPLATE_NULL
sl@0
   192
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs)
sl@0
   193
{ *this = U64Multiply( *this, rhs ); return *this; }
sl@0
   194
_STLP_TEMPLATE_NULL
sl@0
   195
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs)
sl@0
   196
{ *this = U64Divide( *this, rhs, NULL ); return *this; }
sl@0
   197
_STLP_TEMPLATE_NULL
sl@0
   198
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs)
sl@0
   199
{ U64Divide( *this, rhs, this ); return *this; }
sl@0
   200
_STLP_TEMPLATE_NULL
sl@0
   201
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs)
sl@0
   202
{ *this = U64BitwiseAnd( *this, rhs ); return *this; }
sl@0
   203
_STLP_TEMPLATE_NULL
sl@0
   204
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs)
sl@0
   205
{ *this = U64BitwiseOr( *this, rhs ); return *this; }
sl@0
   206
_STLP_TEMPLATE_NULL
sl@0
   207
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs)
sl@0
   208
{ *this = U64BitwiseEor( *this, rhs ); return *this; }
sl@0
   209
sl@0
   210
// Arithmetic op= operations involving built-in integer.
sl@0
   211
_STLP_TEMPLATE_NULL
sl@0
   212
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs)
sl@0
   213
{ *this = U64ShiftLeft( *this, rhs ); return *this; }
sl@0
   214
_STLP_TEMPLATE_NULL
sl@0
   215
inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs)
sl@0
   216
{ *this = U64ShiftRight( *this, rhs ); return *this; }
sl@0
   217
sl@0
   218
// Comparison operators.
sl@0
   219
_STLP_TEMPLATE_NULL
sl@0
   220
inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
sl@0
   221
{ return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
sl@0
   222
_STLP_TEMPLATE_NULL
sl@0
   223
inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
sl@0
   224
{ return U64Compare( lhs, rhs ) < 0; }
sl@0
   225
_STLP_TEMPLATE_NULL
sl@0
   226
inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs)
sl@0
   227
{ return (lhs.hi == 0) && (lhs.lo == rhs); }
sl@0
   228
sl@0
   229
// Unary non-member arithmetic operators.
sl@0
   230
_STLP_TEMPLATE_NULL
sl@0
   231
inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
sl@0
   232
_STLP_TEMPLATE_NULL
sl@0
   233
inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
sl@0
   234
_STLP_TEMPLATE_NULL
sl@0
   235
inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
sl@0
   236
sl@0
   237
#  endif // TYPE_LONGLONG
sl@0
   238
#endif // __MRC__
sl@0
   239
sl@0
   240
#endif // _UINT64_H