1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of wxLongLong class - best implementation of a 64
4 // bit integer for the current platform.
5 // Author: Jeffrey C. Ollie <jeff@ollie.clive.ia.us>, Vadim Zeitlin
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_LONGLONG_H
14 #define _WX_LONGLONG_H
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "longlong.h"
21 #include "wx/string.h"
23 #include <limits.h> // for LONG_MAX
25 // define this to compile wxLongLongWx in "test" mode: the results of all
26 // calculations will be compared with the real results taken from
27 // wxLongLongNative -- this is extremely useful to find the bugs in
28 // wxLongLongWx class!
30 // #define wxLONGLONG_TEST_MODE
32 #ifdef wxLONGLONG_TEST_MODE
33 #define wxUSE_LONGLONG_WX 1
34 #define wxUSE_LONGLONG_NATIVE 1
35 #endif // wxLONGLONG_TEST_MODE
37 // ----------------------------------------------------------------------------
38 // decide upon which class we will use
39 // ----------------------------------------------------------------------------
42 // both warning and pragma warning are not portable, but at least an
43 // unknown pragma should never be an error -- except that, actually, some
44 // broken compilers don't like it, so we have to disable it in this case
46 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
47 #pragma warning "Your compiler does not appear to support 64 bit "\
48 "integers, using emulation class instead.\n" \
49 "Please report your compiler version to " \
50 "wx-dev@lists.wxwidgets.org!"
53 #define wxUSE_LONGLONG_WX 1
56 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
57 // to disable automatic testing (useful for the test program which defines
58 // both classes) but by default we only use one class
59 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
60 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
61 // this is useful in test programs and only there
62 #ifndef wxUSE_LONGLONG_NATIVE
63 #define wxUSE_LONGLONG_NATIVE 0
66 class WXDLLIMPEXP_BASE wxLongLongWx
;
67 class WXDLLIMPEXP_BASE wxULongLongWx
;
68 #if defined(__VISUALC__) && !defined(__WIN32__)
69 #define wxLongLong wxLongLongWx
70 #define wxULongLong wxULongLongWx
72 typedef wxLongLongWx wxLongLong
;
73 typedef wxULongLongWx wxULongLong
;
77 // if nothing is defined, use native implementation by default, of course
78 #ifndef wxUSE_LONGLONG_NATIVE
79 #define wxUSE_LONGLONG_NATIVE 1
83 #ifndef wxUSE_LONGLONG_WX
84 #define wxUSE_LONGLONG_WX 0
85 class WXDLLIMPEXP_BASE wxLongLongNative
;
86 class WXDLLIMPEXP_BASE wxULongLongNative
;
87 typedef wxLongLongNative wxLongLong
;
88 typedef wxULongLongNative wxULongLong
;
91 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
92 // typedef wxLongLong as it wants, we don't do it
94 // ----------------------------------------------------------------------------
95 // choose the appropriate class
96 // ----------------------------------------------------------------------------
98 // we use iostream for wxLongLong output
99 #include "wx/iosfwrap.h"
101 #if wxUSE_LONGLONG_NATIVE
103 class WXDLLIMPEXP_BASE wxLongLongNative
107 // default ctor initializes to 0
108 wxLongLongNative() : m_ll(0) { }
110 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
112 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
114 // assign first to avoid precision loss!
115 m_ll
= ((wxLongLong_t
) hi
) << 32;
116 m_ll
|= (wxLongLong_t
) lo
;
118 #if wxUSE_LONGLONG_WX
119 wxLongLongNative(wxLongLongWx ll
);
122 // default copy ctor is ok
126 // assignment operators
127 // from native 64 bit integer
128 wxLongLongNative
& operator=(wxLongLong_t ll
)
129 { m_ll
= ll
; return *this; }
130 #if wxUSE_LONGLONG_WX
131 wxLongLongNative
& operator=(wxLongLongWx ll
);
135 // from double: this one has an explicit name because otherwise we
136 // would have ambiguity with "ll = int" and also because we don't want
137 // to have implicit conversions between doubles and wxLongLongs
138 wxLongLongNative
& Assign(double d
)
139 { m_ll
= (wxLongLong_t
)d
; return *this; }
141 // assignment operators from wxLongLongNative is ok
146 { return (long)(m_ll
>> 32); }
148 unsigned long GetLo() const
149 { return (unsigned long)m_ll
; }
151 // get absolute value
152 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
153 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
155 // convert to native long long
156 wxLongLong_t
GetValue() const { return m_ll
; }
158 // convert to long with range checking in the debug mode (only!)
161 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
162 _T("wxLongLong to long conversion loss of precision") );
167 // don't provide implicit conversion to wxLongLong_t or we will have an
168 // ambiguity for all arithmetic operations
169 //operator wxLongLong_t() const { return m_ll; }
173 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
174 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
175 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
176 { m_ll
+= ll
.m_ll
; return *this; }
178 wxLongLongNative
operator+(const wxLongLong_t ll
) const
179 { return wxLongLongNative(m_ll
+ ll
); }
180 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
181 { m_ll
+= ll
; return *this; }
184 wxLongLongNative
& operator++()
185 { m_ll
++; return *this; }
188 wxLongLongNative
operator++(int)
189 { wxLongLongNative
value(*this); m_ll
++; return value
; }
192 wxLongLongNative
operator-() const
193 { return wxLongLongNative(-m_ll
); }
194 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
197 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
198 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
199 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
200 { m_ll
-= ll
.m_ll
; return *this; }
202 wxLongLongNative
operator-(const wxLongLong_t ll
) const
203 { return wxLongLongNative(m_ll
- ll
); }
204 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
205 { m_ll
-= ll
; return *this; }
208 wxLongLongNative
& operator--()
209 { m_ll
--; return *this; }
212 wxLongLongNative
operator--(int)
213 { wxLongLongNative
value(*this); m_ll
--; return value
; }
217 wxLongLongNative
operator<<(int shift
) const
218 { return wxLongLongNative(m_ll
<< shift
);; }
219 wxLongLongNative
& operator<<=(int shift
)
220 { m_ll
<<= shift
; return *this; }
223 wxLongLongNative
operator>>(int shift
) const
224 { return wxLongLongNative(m_ll
>> shift
);; }
225 wxLongLongNative
& operator>>=(int shift
)
226 { m_ll
>>= shift
; return *this; }
229 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
230 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
231 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
232 { m_ll
&= ll
.m_ll
; return *this; }
234 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
235 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
236 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
237 { m_ll
|= ll
.m_ll
; return *this; }
239 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
240 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
241 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
242 { m_ll
^= ll
.m_ll
; return *this; }
244 // multiplication/division
245 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
246 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
247 wxLongLongNative
operator*(long l
) const
248 { return wxLongLongNative(m_ll
* l
); }
249 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
250 { m_ll
*= ll
.m_ll
; return *this; }
251 wxLongLongNative
& operator*=(long l
)
252 { m_ll
*= l
; return *this; }
254 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
255 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
256 wxLongLongNative
operator/(long l
) const
257 { return wxLongLongNative(m_ll
/ l
); }
258 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
259 { m_ll
/= ll
.m_ll
; return *this; }
260 wxLongLongNative
& operator/=(long l
)
261 { m_ll
/= l
; return *this; }
263 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
264 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
265 wxLongLongNative
operator%(long l
) const
266 { return wxLongLongNative(m_ll
% l
); }
269 bool operator==(const wxLongLongNative
& ll
) const
270 { return m_ll
== ll
.m_ll
; }
271 bool operator==(long l
) const
272 { return m_ll
== l
; }
273 bool operator!=(const wxLongLongNative
& ll
) const
274 { return m_ll
!= ll
.m_ll
; }
275 bool operator!=(long l
) const
276 { return m_ll
!= l
; }
277 bool operator<(const wxLongLongNative
& ll
) const
278 { return m_ll
< ll
.m_ll
; }
279 bool operator<(long l
) const
281 bool operator>(const wxLongLongNative
& ll
) const
282 { return m_ll
> ll
.m_ll
; }
283 bool operator>(long l
) const
285 bool operator<=(const wxLongLongNative
& ll
) const
286 { return m_ll
<= ll
.m_ll
; }
287 bool operator<=(long l
) const
288 { return m_ll
<= l
; }
289 bool operator>=(const wxLongLongNative
& ll
) const
290 { return m_ll
>= ll
.m_ll
; }
291 bool operator>=(long l
) const
292 { return m_ll
>= l
; }
296 // return the string representation of this number
297 wxString
ToString() const;
299 // conversion to byte array: returns a pointer to static buffer!
300 void *asArray() const;
302 #if wxUSE_STD_IOSTREAM
304 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
307 friend wxString
& operator<<(wxString
&, const wxLongLongNative
&);
314 class WXDLLIMPEXP_BASE wxULongLongNative
318 // default ctor initializes to 0
319 wxULongLongNative() : m_ll(0) { }
321 wxULongLongNative(unsigned wxLongLong_t ll
) : m_ll(ll
) { }
323 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
325 // assign first to avoid precision loss!
326 m_ll
= ((unsigned wxLongLong_t
) hi
) << 32;
327 m_ll
|= (unsigned wxLongLong_t
) lo
;
330 // default copy ctor is ok
334 // assignment operators
335 // from native 64 bit integer
336 wxULongLongNative
& operator=(unsigned wxLongLong_t ll
)
337 { m_ll
= ll
; return *this; }
339 // assignment operators from wxULongLongNative is ok
343 unsigned long GetHi() const
344 { return (unsigned long)(m_ll
>> 32); }
346 unsigned long GetLo() const
347 { return (unsigned long)m_ll
; }
349 // convert to native ulong long
350 unsigned wxLongLong_t
GetValue() const { return m_ll
; }
352 // convert to ulong with range checking in the debug mode (only!)
353 unsigned long ToULong() const
355 wxASSERT_MSG( m_ll
<= LONG_MAX
,
356 _T("wxULongLong to long conversion loss of precision") );
358 return (unsigned long)m_ll
;
363 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
364 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
365 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
366 { m_ll
+= ll
.m_ll
; return *this; }
368 wxULongLongNative
operator+(const unsigned wxLongLong_t ll
) const
369 { return wxULongLongNative(m_ll
+ ll
); }
370 wxULongLongNative
& operator+=(const unsigned wxLongLong_t ll
)
371 { m_ll
+= ll
; return *this; }
374 wxULongLongNative
& operator++()
375 { m_ll
++; return *this; }
378 wxULongLongNative
operator++(int)
379 { wxULongLongNative
value(*this); m_ll
++; return value
; }
382 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
383 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
384 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
385 { m_ll
-= ll
.m_ll
; return *this; }
387 wxULongLongNative
operator-(const unsigned wxLongLong_t ll
) const
388 { return wxULongLongNative(m_ll
- ll
); }
389 wxULongLongNative
& operator-=(const unsigned wxLongLong_t ll
)
390 { m_ll
-= ll
; return *this; }
393 wxULongLongNative
& operator--()
394 { m_ll
--; return *this; }
397 wxULongLongNative
operator--(int)
398 { wxULongLongNative
value(*this); m_ll
--; return value
; }
402 wxULongLongNative
operator<<(int shift
) const
403 { return wxULongLongNative(m_ll
<< shift
);; }
404 wxULongLongNative
& operator<<=(int shift
)
405 { m_ll
<<= shift
; return *this; }
408 wxULongLongNative
operator>>(int shift
) const
409 { return wxULongLongNative(m_ll
>> shift
);; }
410 wxULongLongNative
& operator>>=(int shift
)
411 { m_ll
>>= shift
; return *this; }
414 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
415 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
416 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
417 { m_ll
&= ll
.m_ll
; return *this; }
419 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
420 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
421 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
422 { m_ll
|= ll
.m_ll
; return *this; }
424 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
425 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
426 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
427 { m_ll
^= ll
.m_ll
; return *this; }
429 // multiplication/division
430 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
431 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
432 wxULongLongNative
operator*(unsigned long l
) const
433 { return wxULongLongNative(m_ll
* l
); }
434 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
435 { m_ll
*= ll
.m_ll
; return *this; }
436 wxULongLongNative
& operator*=(unsigned long l
)
437 { m_ll
*= l
; return *this; }
439 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
440 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
441 wxULongLongNative
operator/(unsigned long l
) const
442 { return wxULongLongNative(m_ll
/ l
); }
443 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
444 { m_ll
/= ll
.m_ll
; return *this; }
445 wxULongLongNative
& operator/=(unsigned long l
)
446 { m_ll
/= l
; return *this; }
448 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
449 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
450 wxULongLongNative
operator%(unsigned long l
) const
451 { return wxULongLongNative(m_ll
% l
); }
454 bool operator==(const wxULongLongNative
& ll
) const
455 { return m_ll
== ll
.m_ll
; }
456 bool operator==(unsigned long l
) const
457 { return m_ll
== l
; }
458 bool operator!=(const wxULongLongNative
& ll
) const
459 { return m_ll
!= ll
.m_ll
; }
460 bool operator!=(unsigned long l
) const
461 { return m_ll
!= l
; }
462 bool operator<(const wxULongLongNative
& ll
) const
463 { return m_ll
< ll
.m_ll
; }
464 bool operator<(unsigned long l
) const
466 bool operator>(const wxULongLongNative
& ll
) const
467 { return m_ll
> ll
.m_ll
; }
468 bool operator>(unsigned long l
) const
470 bool operator<=(const wxULongLongNative
& ll
) const
471 { return m_ll
<= ll
.m_ll
; }
472 bool operator<=(unsigned long l
) const
473 { return m_ll
<= l
; }
474 bool operator>=(const wxULongLongNative
& ll
) const
475 { return m_ll
>= ll
.m_ll
; }
476 bool operator>=(unsigned long l
) const
477 { return m_ll
>= l
; }
481 // return the string representation of this number
482 wxString
ToString() const;
484 // conversion to byte array: returns a pointer to static buffer!
485 void *asArray() const;
487 #if wxUSE_STD_IOSTREAM
489 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
492 friend wxString
& operator<<(wxString
&, const wxULongLongNative
&);
495 unsigned wxLongLong_t m_ll
;
498 #endif // wxUSE_LONGLONG_NATIVE
500 #if wxUSE_LONGLONG_WX
502 class WXDLLIMPEXP_BASE wxLongLongWx
506 // default ctor initializes to 0
511 #ifdef wxLONGLONG_TEST_MODE
515 #endif // wxLONGLONG_TEST_MODE
518 wxLongLongWx(long l
) { *this = l
; }
520 wxLongLongWx(long hi
, unsigned long lo
)
525 #ifdef wxLONGLONG_TEST_MODE
531 #endif // wxLONGLONG_TEST_MODE
534 // default copy ctor is ok in both cases
538 // assignment operators
540 wxLongLongWx
& operator=(long l
)
543 m_hi
= (l
< 0 ? -1l : 0l);
545 #ifdef wxLONGLONG_TEST_MODE
549 #endif // wxLONGLONG_TEST_MODE
554 wxLongLongWx
& Assign(double d
);
555 // can't have assignment operator from 2 longs
559 long GetHi() const { return m_hi
; }
561 unsigned long GetLo() const { return m_lo
; }
563 // get absolute value
564 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
570 #ifdef wxLONGLONG_TEST_MODE
575 #endif // wxLONGLONG_TEST_MODE
580 // convert to long with range checking in the debug mode (only!)
583 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
584 _T("wxLongLong to long conversion loss of precision") );
591 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
592 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
593 wxLongLongWx
operator+(long l
) const;
594 wxLongLongWx
& operator+=(long l
);
596 // pre increment operator
597 wxLongLongWx
& operator++();
599 // post increment operator
600 wxLongLongWx
& operator++(int) { return ++(*this); }
603 wxLongLongWx
operator-() const;
604 wxLongLongWx
& Negate();
607 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
608 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
610 // pre decrement operator
611 wxLongLongWx
& operator--();
613 // post decrement operator
614 wxLongLongWx
& operator--(int) { return --(*this); }
618 wxLongLongWx
operator<<(int shift
) const;
619 wxLongLongWx
& operator<<=(int shift
);
622 wxLongLongWx
operator>>(int shift
) const;
623 wxLongLongWx
& operator>>=(int shift
);
626 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
627 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
628 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
629 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
630 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
631 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
632 wxLongLongWx
operator~() const;
635 bool operator==(const wxLongLongWx
& ll
) const
636 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
637 #if wxUSE_LONGLONG_NATIVE
638 bool operator==(const wxLongLongNative
& ll
) const
639 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
641 bool operator!=(const wxLongLongWx
& ll
) const
642 { return !(*this == ll
); }
643 bool operator<(const wxLongLongWx
& ll
) const;
644 bool operator>(const wxLongLongWx
& ll
) const;
645 bool operator<=(const wxLongLongWx
& ll
) const
646 { return *this < ll
|| *this == ll
; }
647 bool operator>=(const wxLongLongWx
& ll
) const
648 { return *this > ll
|| *this == ll
; }
650 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
651 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
652 bool operator==(long l
) const
654 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
655 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
658 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
659 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
662 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
663 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
666 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
667 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
669 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
671 void Divide(const wxLongLongWx
& divisor
,
672 wxLongLongWx
& quotient
,
673 wxLongLongWx
& remainder
) const;
677 // return the string representation of this number
678 wxString
ToString() const;
680 void *asArray() const;
682 #if wxUSE_STD_IOSTREAM
683 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
684 #endif // wxUSE_STD_IOSTREAM
686 friend wxString
& operator<<(wxString
&, const wxLongLongWx
&);
689 // long is at least 32 bits, so represent our 64bit number as 2 longs
691 long m_hi
; // signed bit is in the high part
694 #ifdef wxLONGLONG_TEST_MODE
697 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
701 #endif // wxLONGLONG_TEST_MODE
705 class WXDLLIMPEXP_BASE wxULongLongWx
709 // default ctor initializes to 0
714 #ifdef wxLONGLONG_TEST_MODE
718 #endif // wxLONGLONG_TEST_MODE
721 wxULongLongWx(unsigned long l
) { *this = l
; }
723 wxULongLongWx(unsigned long hi
, unsigned long lo
)
728 #ifdef wxLONGLONG_TEST_MODE
734 #endif // wxLONGLONG_TEST_MODE
737 // from signed to unsigned
738 wxULongLongWx(wxLongLongWx ll
)
740 wxASSERT(ll
.GetHi() >= 0);
741 m_hi
= (unsigned long)ll
.GetHi();
745 // default copy ctor is ok in both cases
749 // assignment operators
751 wxULongLongWx
& operator=(unsigned long l
)
756 #ifdef wxLONGLONG_TEST_MODE
760 #endif // wxLONGLONG_TEST_MODE
765 // can't have assignment operator from 2 longs
769 unsigned long GetHi() const { return m_hi
; }
771 unsigned long GetLo() const { return m_lo
; }
773 // convert to long with range checking in the debug mode (only!)
774 unsigned long ToULong() const
776 wxASSERT_MSG( m_hi
== 0ul,
777 _T("wxULongLong to long conversion loss of precision") );
779 return (unsigned long)m_lo
;
784 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
785 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
786 wxULongLongWx
operator+(unsigned long l
) const;
787 wxULongLongWx
& operator+=(unsigned long l
);
789 // pre increment operator
790 wxULongLongWx
& operator++();
792 // post increment operator
793 wxULongLongWx
& operator++(int) { return ++(*this); }
796 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
797 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
799 // pre decrement operator
800 wxULongLongWx
& operator--();
802 // post decrement operator
803 wxULongLongWx
& operator--(int) { return --(*this); }
807 wxULongLongWx
operator<<(int shift
) const;
808 wxULongLongWx
& operator<<=(int shift
);
811 wxULongLongWx
operator>>(int shift
) const;
812 wxULongLongWx
& operator>>=(int shift
);
815 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
816 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
817 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
818 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
819 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
820 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
821 wxULongLongWx
operator~() const;
824 bool operator==(const wxULongLongWx
& ll
) const
825 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
826 bool operator!=(const wxULongLongWx
& ll
) const
827 { return !(*this == ll
); }
828 bool operator<(const wxULongLongWx
& ll
) const;
829 bool operator>(const wxULongLongWx
& ll
) const;
830 bool operator<=(const wxULongLongWx
& ll
) const
831 { return *this < ll
|| *this == ll
; }
832 bool operator>=(const wxULongLongWx
& ll
) const
833 { return *this > ll
|| *this == ll
; }
835 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
836 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
837 bool operator==(unsigned long l
) const
839 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
842 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
843 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
846 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
847 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
850 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
851 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
853 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
855 void Divide(const wxULongLongWx
& divisor
,
856 wxULongLongWx
& quotient
,
857 wxULongLongWx
& remainder
) const;
861 // return the string representation of this number
862 wxString
ToString() const;
864 void *asArray() const;
866 #if wxUSE_STD_IOSTREAM
867 friend wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
868 #endif // wxUSE_STD_IOSTREAM
870 friend wxString
& operator<<(wxString
&, const wxULongLongWx
&);
873 // long is at least 32 bits, so represent our 64bit number as 2 longs
878 #ifdef wxLONGLONG_TEST_MODE
881 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
884 unsigned wxLongLong_t m_ll
;
885 #endif // wxLONGLONG_TEST_MODE
888 #endif // wxUSE_LONGLONG_WX
890 // ----------------------------------------------------------------------------
892 // ----------------------------------------------------------------------------
894 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
895 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
896 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
897 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
898 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
899 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
901 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
902 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
904 return wxLongLong(l
) - ll
;
907 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
908 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
909 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
910 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
911 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
912 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
914 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
916 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
918 wxULongLong ret
= wxULongLong(l
) - ull
;
919 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
922 #endif // _WX_LONGLONG_H