]>
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"
30 #include "wx/longlong.h"
32 #include <memory.h> // for memset()
34 // ============================================================================
36 // ============================================================================
38 #if wxUSE_LONGLONG_NATIVE
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 void *wxLongLongNative::asArray(void) const
46 static unsigned char temp
[8];
48 temp
[0] = (m_ll
>> 56) & 0xFF;
49 temp
[1] = (m_ll
>> 48) & 0xFF;
50 temp
[2] = (m_ll
>> 40) & 0xFF;
51 temp
[3] = (m_ll
>> 32) & 0xFF;
52 temp
[4] = (m_ll
>> 24) & 0xFF;
53 temp
[5] = (m_ll
>> 16) & 0xFF;
54 temp
[6] = (m_ll
>> 8) & 0xFF;
55 temp
[7] = (m_ll
>> 0) & 0xFF;
61 ostream
& operator<< (ostream
& o
, const wxLongLongNative
& ll
)
65 memset(result
, 'A', 64);
69 for (int i
= 0; i
< 64; i
++)
71 result
[63 - i
] = '0' + (char) ((ll
.m_ll
>> i
) & 1);
77 #endif // wxUSE_LONGLONG_NATIVE
81 wxLongLongWx
wxLongLongWx::operator<<(int shift
) const
87 return wxLongLongWx((m_hi
<< shift
) | (m_lo
>> (32 - shift
)),
90 return wxLongLongWx(m_lo
<< (shift
- 32),
94 wxLongLongWx
& wxLongLongWx::operator<<=(int shift
)
102 m_hi
|= m_lo
>> (32 - shift
);
107 m_hi
= m_lo
<< (shift
- 32);
114 wxLongLongWx
wxLongLongWx::operator>>(int shift
) const
120 return wxLongLongWx(m_hi
>> shift
,
121 (m_lo
>> shift
) | (m_hi
<< (32 - shift
)));
123 return wxLongLongWx((m_hi
< 0 ? -1l : 0),
124 m_hi
>> (shift
- 32));
127 wxLongLongWx
& wxLongLongWx::operator>>=(int shift
)
135 m_lo
|= m_hi
<< (32 - shift
);
140 m_lo
= m_hi
>> (shift
- 32);
141 m_hi
= (m_hi
< 0 ? -1L : 0);
147 wxLongLongWx
wxLongLongWx::operator+(const wxLongLongWx
& ll
) const
151 temp
.m_lo
= m_lo
+ ll
.m_lo
;
152 temp
.m_hi
= m_hi
+ ll
.m_hi
;
153 if ((temp
.m_lo
< m_lo
) || (temp
.m_lo
< ll
.m_lo
))
159 wxLongLongWx
wxLongLongWx::operator+(long l
) const
163 temp
.m_lo
= m_lo
+ l
;
168 if ((temp
.m_lo
< m_lo
) || (temp
.m_lo
< (unsigned long)l
))
174 wxLongLongWx
& wxLongLongWx::operator+=(const wxLongLongWx
& ll
)
176 unsigned long previous
= m_lo
;
181 if ((m_lo
< previous
) || (m_lo
< ll
.m_lo
))
187 wxLongLongWx
& wxLongLongWx::operator+=(long l
)
189 unsigned long previous
= m_lo
;
195 if ((m_lo
< previous
) || (m_lo
< (unsigned long)l
))
202 wxLongLongWx
& wxLongLongWx::operator++()
212 wxLongLongWx
& wxLongLongWx::operator++(int)
222 wxLongLongWx
wxLongLongWx::operator-() const
224 wxLongLongWx
temp(~m_hi
, ~m_lo
);
235 wxLongLongWx
wxLongLongWx::operator-(const wxLongLongWx
& ll
) const
239 temp
.m_lo
= m_lo
- ll
.m_lo
;
240 temp
.m_hi
= m_hi
- ll
.m_hi
;
248 wxLongLongWx
& wxLongLongWx::operator-=(const wxLongLongWx
& ll
)
250 unsigned long previous
= m_lo
;
255 if (previous
< ll
.m_lo
)
262 wxLongLongWx
& wxLongLongWx::operator--()
265 if (m_lo
== 0xFFFFFFFF)
272 wxLongLongWx
& wxLongLongWx::operator--(int)
275 if (m_lo
== 0xFFFFFFFF)
281 // comparison operators
283 bool wxLongLongWx::operator<(const wxLongLongWx
& ll
) const
296 bool wxLongLongWx::operator>(const wxLongLongWx
& ll
) const
309 bool wxLongLongWx::operator<=(const wxLongLongWx
& ll
) const
322 bool wxLongLongWx::operator>=(const wxLongLongWx
& ll
) const
337 wxLongLongWx
wxLongLongWx::operator&(const wxLongLongWx
& ll
) const
339 return wxLongLongWx(m_hi
& ll
.m_hi
, m_lo
& ll
.m_lo
);
342 wxLongLongWx
wxLongLongWx::operator|(const wxLongLongWx
& ll
) const
344 return wxLongLongWx(m_hi
| ll
.m_hi
, m_lo
| ll
.m_lo
);
347 wxLongLongWx
wxLongLongWx::operator^(const wxLongLongWx
& ll
) const
349 return wxLongLongWx(m_hi
^ ll
.m_hi
, m_lo
^ ll
.m_lo
);
352 wxLongLongWx
& wxLongLongWx::operator&=(const wxLongLongWx
& ll
)
360 wxLongLongWx
& wxLongLongWx::operator|=(const wxLongLongWx
& ll
)
368 wxLongLongWx
& wxLongLongWx::operator^=(const wxLongLongWx
& ll
)
376 wxLongLongWx
wxLongLongWx::operator~() const
378 return wxLongLongWx(~m_hi
, ~m_lo
);
383 wxLongLongWx
wxLongLongWx::operator*(const wxLongLongWx
& ll
) const
385 wxLongLongWx
t(m_hi
, m_lo
);
386 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
392 if ((q
.m_lo
& 1) != 0)
398 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
402 wxLongLongWx
& wxLongLongWx::operator*=(const wxLongLongWx
& ll
)
404 wxLongLongWx
t(m_hi
, m_lo
);
405 wxLongLongWx
q(ll
.m_hi
, ll
.m_lo
);
410 if ((q
.m_lo
& 1) != 0)
416 while ((counter
< 64) && ((q
.m_hi
!= 0) || (q
.m_lo
!= 0)));
422 void wxLongLongWx::Divide(const wxLongLongWx
& divisor
, wxLongLongWx
& quotient
, wxLongLongWx
& remainder
) const
424 if ((divisor
.m_lo
== 0) && (divisor
.m_hi
== 0))
426 // provoke division by zero error and silence the compilers warnings
427 // about an expression without effect and unused variable
428 long dummy
= divisor
.m_lo
/divisor
.m_hi
;
432 wxFAIL_MSG("not implemented");
435 // temporary - just for testing
436 void *wxLongLongWx::asArray(void) const
438 static unsigned char temp
[8];
440 temp
[0] = (m_hi
>> 24) & 0xFF;
441 temp
[1] = (m_hi
>> 16) & 0xFF;
442 temp
[2] = (m_hi
>> 8) & 0xFF;
443 temp
[3] = (m_hi
>> 0) & 0xFF;
444 temp
[4] = (m_lo
>> 24) & 0xFF;
445 temp
[5] = (m_lo
>> 16) & 0xFF;
446 temp
[6] = (m_lo
>> 8) & 0xFF;
447 temp
[7] = (m_lo
>> 0) & 0xFF;
454 ostream
& operator<< (ostream
& o
, const wxLongLongWx
& ll
)
458 memset(result
, 'A', 64);
462 for (int i
= 0; i
< 32; i
++)
464 result
[31 - i
] = (char) ('0' + (int) ((ll
.m_hi
>> i
) & 1));
465 result
[63 - i
] = (char) ('0' + (int) ((ll
.m_lo
>> i
) & 1));
471 // wxUSE_LONGLONG_NATIVE
473 #endif // wxUSE_LONGLONG