]>
git.saurik.com Git - wxWidgets.git/blob - src/common/longlong.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/longlong.cpp
3 // Purpose: implementation of wxLongLongNative
4 // Author: Jeffrey C. Ollie <jeff@ollie.clive.ia.us>, Vadim Zeitlin
5 // Remarks: this class is not public in wxWindows 2.0! It is intentionally
6 // not documented and is for private use only.
10 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
11 // Licence: wxWindows license
12 /////////////////////////////////////////////////////////////////////////////
14 // ============================================================================
16 // ============================================================================
19 #pragma implementation "longlong.h"
22 #include "wx/wxprec.h"
28 #include "wx/longlong.h"
30 #include <memory.h> // for memset()
32 // ============================================================================
34 // ============================================================================
36 #if wxUSE_LONGLONG_NATIVE
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 void *wxLongLongNative::asArray(void) const
44 static unsigned char temp
[8];
46 temp
[0] = (m_ll
>> 56) & 0xFF;
47 temp
[1] = (m_ll
>> 48) & 0xFF;
48 temp
[2] = (m_ll
>> 40) & 0xFF;
49 temp
[3] = (m_ll
>> 32) & 0xFF;
50 temp
[4] = (m_ll
>> 24) & 0xFF;
51 temp
[5] = (m_ll
>> 16) & 0xFF;
52 temp
[6] = (m_ll
>> 8) & 0xFF;
53 temp
[7] = (m_ll
>> 0) & 0xFF;
59 ostream
& operator<< (ostream
& o
, const wxLongLongNative
& ll
)
63 memset(result
, 'A', 64);
67 for (int i
= 0; i
< 64; i
++)
69 result
[63 - i
] = '0' + (char) ((ll
.m_ll
>> i
) & 1);
75 #endif // wxUSE_LONGLONG_NATIVE
79 wxLongLongWx
wxLongLongWx::operator<<(int shift
) const
85 return wxLongLongWx((m_hi
<< shift
) | (m_lo
>> (32 - shift
)),
88 return wxLongLongWx(m_lo
<< (shift
- 32),
92 wxLongLongWx
& wxLongLongWx::operator<<=(int shift
)
100 m_hi
|= m_lo
>> (32 - shift
);
105 m_hi
= m_lo
<< (shift
- 32);
112 wxLongLongWx
wxLongLongWx::operator>>(int shift
) const
118 return wxLongLongWx(m_hi
>> shift
,
119 (m_lo
>> shift
) | (m_hi
<< (32 - shift
)));
121 return wxLongLongWx((m_hi
< 0 ? -1l : 0),
122 m_hi
>> (shift
- 32));
125 wxLongLongWx
& wxLongLongWx::operator>>=(int shift
)
133 m_lo
|= m_hi
<< (32 - shift
);
138 m_lo
= m_hi
>> (shift
- 32);
139 m_hi
= (m_hi
< 0 ? -1L : 0);
145 wxLongLongWx
wxLongLongWx::operator+(const wxLongLongWx
& ll
) const
149 temp
.m_lo
= m_lo
+ ll
.m_lo
;
150 temp
.m_hi
= m_hi
+ ll
.m_hi
;
151 if ((temp
.m_lo
< m_lo
) || (temp
.m_lo
< ll
.m_lo
))
157 wxLongLongWx
wxLongLongWx::operator+(long l
) const
161 temp
.m_lo
= m_lo
+ l
;
166 if ((temp
.m_lo
< m_lo
) || (temp
.m_lo
< (unsigned long)l
))
172 wxLongLongWx
& wxLongLongWx::operator+=(const wxLongLongWx
& ll
)
174 unsigned long previous
= m_lo
;
179 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
185 wxLongLongWx
& wxLongLongWx::operator+=(long l
)
187 unsigned long previous
= m_lo
;
193 if ((m_lo
< previous
) || (m_lo
< (unsigned long)l
))
200 wxLongLongWx
& wxLongLongWx::operator++()
210 wxLongLongWx
& wxLongLongWx::operator++(int)
220 wxLongLongWx
wxLongLongWx::operator-() const
222 wxLongLongWx
temp(~m_hi
, ~m_lo
);
233 wxLongLongWx
wxLongLongWx::operator-(const wxLongLongWx
& ll
) const
237 temp
.m_lo
= m_lo
- ll
.m_lo
;
238 temp
.m_hi
= m_hi
- ll
.m_hi
;
246 wxLongLongWx
& wxLongLongWx::operator-=(const wxLongLongWx
& ll
)
248 unsigned long previous
= m_lo
;
253 if (previous
< ll
.m_lo
)
260 wxLongLongWx
& wxLongLongWx::operator--()
263 if (m_lo
== 0xFFFFFFFF)
270 wxLongLongWx
& wxLongLongWx::operator--(int)
273 if (m_lo
== 0xFFFFFFFF)
279 // comparison operators
281 bool wxLongLongWx::operator<(const wxLongLongWx
& ll
) const
294 bool wxLongLongWx::operator>(const wxLongLongWx
& ll
) const
307 bool wxLongLongWx::operator<=(const wxLongLongWx
& ll
) const
320 bool wxLongLongWx::operator>=(const wxLongLongWx
& ll
) const
335 wxLongLongWx
wxLongLongWx::operator&(const wxLongLongWx
& ll
) const
337 return wxLongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
340 wxLongLongWx
wxLongLongWx::operator|(const wxLongLongWx
& ll
) const
342 return wxLongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
345 wxLongLongWx
wxLongLongWx::operator^(const wxLongLongWx
& ll
) const
347 return wxLongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
350 wxLongLongWx
& wxLongLongWx::operator&=(const wxLongLongWx
& ll
)
358 wxLongLongWx
& wxLongLongWx::operator|=(const wxLongLongWx
& ll
)
366 wxLongLongWx
& wxLongLongWx::operator^=(const wxLongLongWx
& ll
)
374 wxLongLongWx
wxLongLongWx::operator~() const
376 return wxLongLongWx(~m_hi
, ~m_lo
);
381 wxLongLongWx
wxLongLongWx::operator*(const wxLongLongWx
& ll
) const
383 wxLongLongWx
t(m_hi
, m_lo
);
384 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
390 if ((q
.m_lo
& 1) != 0)
396 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
400 wxLongLongWx
& wxLongLongWx::operator*=(const wxLongLongWx
& ll
)
402 wxLongLongWx
t(m_hi
, m_lo
);
403 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
408 if ((q
.m_lo
& 1) != 0)
414 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
420 void wxLongLongWx::Divide(const wxLongLongWx
& divisor
, wxLongLongWx
& quotient
, wxLongLongWx
& remainder
) const
422 if ((divisor
.m_lo
== 0) && (divisor
.m_hi
== 0))
424 // provoke division by zero error and silence the compilers warnings
425 // about an expression without effect and unused variable
426 long dummy
= divisor
.m_lo
/divisor
.m_hi
;
430 wxFAIL_MSG("not implemented");
433 // temporary - just for testing
434 void *wxLongLongWx::asArray(void) const
436 static unsigned char temp
[8];
438 temp
[0] = (m_hi
>> 24) & 0xFF;
439 temp
[1] = (m_hi
>> 16) & 0xFF;
440 temp
[2] = (m_hi
>> 8) & 0xFF;
441 temp
[3] = (m_hi
>> 0) & 0xFF;
442 temp
[4] = (m_lo
>> 24) & 0xFF;
443 temp
[5] = (m_lo
>> 16) & 0xFF;
444 temp
[6] = (m_lo
>> 8) & 0xFF;
445 temp
[7] = (m_lo
>> 0) & 0xFF;
452 ostream
& operator<< (ostream
& o
, const wxLongLongWx
& ll
)
456 memset(result
, 'A', 64);
460 for (int i
= 0; i
< 32; i
++)
462 result
[31 - i
] = (char) ('0' + (int) ((ll
.m_hi
>> i
) & 1));
463 result
[63 - i
] = (char) ('0' + (int) ((ll
.m_lo
>> i
) & 1));
469 // wxUSE_LONGLONG_NATIVE