3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2004 David Ward
7 /////////////////////////////////////////////////////////////////////////////
12 #include "../myassert.h"
21 #define NON_STANDARD_LL
24 #define NON_STANDARD_LL
29 #ifdef NON_STANDARD_LL
30 const int64 int64_0xffffffff80000000LL
= 0xffffffff80000000i
64;
31 const uint64 uint64_0xffffffff00000000ULL
= 0xffffffff80000000ui
64;
33 const int64 int64_0xffffffff80000000LL
= 0xffffffff80000000LL
;
34 const uint64 uint64_0xffffffff00000000ULL
= 0xffffffff00000000ULL
;
40 return std::numeric_limits
< int32
>::max();
43 return std::numeric_limits
< int32
>::min();
49 Cint32(int32 i
):m_i(i
) {
55 if(d
> double (Cint32::Max()))
58 if(d
< double (Cint32::Min()))
65 operator double () const {
68 operator long () const {
71 operator int64() const {
74 operator int32() const {
77 Cint32
& operator+=(Cint32 rhs
) {
78 if(!AreDifferentSigns(m_i
, rhs
.m_i
)) {
82 if(m_i
< Min() - rhs
.m_i
) {
89 if(Max() - m_i
< rhs
.m_i
) {
99 Cint32
& operator-=(Cint32 rhs
) {
100 if(AreDifferentSigns(m_i
, rhs
.m_i
)) {
103 if(m_i
> Max() + rhs
.m_i
) {
109 if(m_i
< Min() + rhs
.m_i
)
118 Cint32
& operator*=(Cint32 rhs
) {
120 int64 tmp
= (int64
) m_i
* (int64
) rhs
.m_i
;
122 // upper 33 bits must be equal
123 if((tmp
& int64_0xffffffff80000000LL
) == 0 || (tmp
& int64_0xffffffff80000000LL
) == int64_0xffffffff80000000LL
) {
132 Cint32
& operator/=(Cint32 rhs
) {
136 // corner case where this = Min and rhs = -1
137 if(m_i
== Min() && rhs
.m_i
== -1)
144 bool operator!=(Cint32 rhs
) const {
145 return m_i
!= rhs
.m_i
;
147 bool operator<=(int rhs
)const {
150 bool operator>=(int rhs
)const {
153 bool operator<(int rhs
)const {
156 bool operator>(int rhs
)const {
159 bool operator<(Cint32 rhs
) const {
160 return m_i
< rhs
.m_i
;
162 bool operator>(Cint32 rhs
) const {
163 return m_i
> rhs
.m_i
;
165 bool operator<=(Cint32 rhs
) const {
166 return m_i
<= rhs
.m_i
;
168 bool operator>=(Cint32 rhs
) const {
169 return m_i
>= rhs
.m_i
;
175 inline Cint32
operator +(Cint32 lhs
, Cint32 rhs
) {
180 inline Cint32
operator +(Cint32 lhs
, int rhs
) {
185 inline double operator +(double lhs
, Cint32 rhs
) {
186 return lhs
+ double (rhs
);
189 inline double operator +(Cint32 lhs
, double rhs
) {
190 return double (lhs
) + rhs
;
193 inline Cint32
operator +(int lhs
, Cint32 rhs
) {
198 inline Cint32
operator -(Cint32 lhs
, Cint32 rhs
) {
203 inline double operator -(double lhs
, Cint32 rhs
) {
204 return lhs
- double (rhs
);
207 inline double operator -(Cint32 lhs
, double rhs
) {
208 return double (lhs
) - rhs
;
211 inline Cint32
operator -(Cint32 lhs
, int rhs
) {
216 inline Cint32
operator -(int lhs
, Cint32 rhs
) {
222 inline Cint32
operator *(Cint32 lhs
, int rhs
) {
227 inline Cint32
operator *(int lhs
, Cint32 rhs
) {
233 inline Cint32
operator *(Cint32 lhs
, Cint32 rhs
) {
238 /*inline Cint32 operator *(int lhs, Cint32 rhs)
245 inline double operator *(double lhs
, Cint32 rhs
) {
246 return lhs
* double (rhs
);
249 inline double operator *(Cint32 lhs
, double rhs
) {
250 return rhs
* double (lhs
);
253 inline Cint32
operator /(Cint32 lhs
, int rhs
) {
258 inline Cint32
operator /(Cint32 lhs
, Cint32 rhs
) {
263 inline Cint32
operator /(int lhs
, Cint32 rhs
) {
269 inline double operator /(Cint32 lhs
, double rhs
) {
270 return double (lhs
) / rhs
;
273 inline double operator /(double lhs
, Cint32 rhs
) {
274 return lhs
/ double (rhs
);
277 inline bool operator >(double lhs
, Cint32 rhs
) {
278 return lhs
> double (rhs
);
281 inline bool operator >(long lhs
, Cint32 rhs
) {
282 return lhs
> long (rhs
);
285 inline bool operator <(long lhs
, Cint32 rhs
) {
286 return lhs
< long (rhs
);
291 inline Cint32::Cint32(Cint64 i
) {
292 if((int64
) i
> int64(Cint32::Max()))
294 if((int64
) i
< int64(Cint32::Min()))
300 inline Cint32
abs(Cint32 t
) {
301 return Cint32(abs(int32(t
)));
306 typedef int32 Cint32
;
310 #endif // __include__