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
17 #include "wx/string.h"
19 #include <limits.h> // for LONG_MAX
21 // define this to compile wxLongLongWx in "test" mode: the results of all
22 // calculations will be compared with the real results taken from
23 // wxLongLongNative -- this is extremely useful to find the bugs in
24 // wxLongLongWx class!
26 // #define wxLONGLONG_TEST_MODE
28 #ifdef wxLONGLONG_TEST_MODE
29 #define wxUSE_LONGLONG_WX 1
30 #define wxUSE_LONGLONG_NATIVE 1
31 #endif // wxLONGLONG_TEST_MODE
33 // ----------------------------------------------------------------------------
34 // decide upon which class we will use
35 // ----------------------------------------------------------------------------
38 // both warning and pragma warning are not portable, but at least an
39 // unknown pragma should never be an error -- except that, actually, some
40 // broken compilers don't like it, so we have to disable it in this case
42 #if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
43 #pragma warning "Your compiler does not appear to support 64 bit "\
44 "integers, using emulation class instead.\n" \
45 "Please report your compiler version to " \
46 "wx-dev@lists.wxwidgets.org!"
49 #define wxUSE_LONGLONG_WX 1
52 // the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
53 // to disable automatic testing (useful for the test program which defines
54 // both classes) but by default we only use one class
55 #if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
56 // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
57 // this is useful in test programs and only there
58 #ifndef wxUSE_LONGLONG_NATIVE
59 #define wxUSE_LONGLONG_NATIVE 0
62 class WXDLLIMPEXP_BASE wxLongLongWx
;
63 class WXDLLIMPEXP_BASE wxULongLongWx
;
64 #if defined(__VISUALC__) && !defined(__WIN32__)
65 #define wxLongLong wxLongLongWx
66 #define wxULongLong wxULongLongWx
68 typedef wxLongLongWx wxLongLong
;
69 typedef wxULongLongWx wxULongLong
;
73 // if nothing is defined, use native implementation by default, of course
74 #ifndef wxUSE_LONGLONG_NATIVE
75 #define wxUSE_LONGLONG_NATIVE 1
79 #ifndef wxUSE_LONGLONG_WX
80 #define wxUSE_LONGLONG_WX 0
81 class WXDLLIMPEXP_BASE wxLongLongNative
;
82 class WXDLLIMPEXP_BASE wxULongLongNative
;
83 typedef wxLongLongNative wxLongLong
;
84 typedef wxULongLongNative wxULongLong
;
87 // NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
88 // typedef wxLongLong as it wants, we don't do it
90 // ----------------------------------------------------------------------------
91 // choose the appropriate class
92 // ----------------------------------------------------------------------------
94 // we use iostream for wxLongLong output
95 #include "wx/iosfwrap.h"
97 #if wxUSE_LONGLONG_NATIVE
99 class WXDLLIMPEXP_BASE wxLongLongNative
103 // default ctor initializes to 0
104 wxLongLongNative() : m_ll(0) { }
106 wxLongLongNative(wxLongLong_t ll
) : m_ll(ll
) { }
108 wxLongLongNative(long hi
, unsigned long lo
) : m_ll(0)
110 // assign first to avoid precision loss!
111 m_ll
= ((wxLongLong_t
) hi
) << 32;
112 m_ll
|= (wxLongLong_t
) lo
;
114 #if wxUSE_LONGLONG_WX
115 wxLongLongNative(wxLongLongWx ll
);
118 // default copy ctor is ok
122 // assignment operators
123 // from native 64 bit integer
124 wxLongLongNative
& operator=(wxLongLong_t ll
)
125 { m_ll
= ll
; return *this; }
126 #if wxUSE_LONGLONG_WX
127 wxLongLongNative
& operator=(wxLongLongWx ll
);
131 // from double: this one has an explicit name because otherwise we
132 // would have ambiguity with "ll = int" and also because we don't want
133 // to have implicit conversions between doubles and wxLongLongs
134 wxLongLongNative
& Assign(double d
)
135 { m_ll
= (wxLongLong_t
)d
; return *this; }
137 // assignment operators from wxLongLongNative is ok
142 { return wx_truncate_cast(long, m_ll
>> 32); }
144 unsigned long GetLo() const
145 { return wx_truncate_cast(unsigned long, m_ll
); }
147 // get absolute value
148 wxLongLongNative
Abs() const { return wxLongLongNative(*this).Abs(); }
149 wxLongLongNative
& Abs() { if ( m_ll
< 0 ) m_ll
= -m_ll
; return *this; }
151 // convert to native long long
152 wxLongLong_t
GetValue() const { return m_ll
; }
154 // convert to long with range checking in the debug mode (only!)
157 wxASSERT_MSG( (m_ll
>= LONG_MIN
) && (m_ll
<= LONG_MAX
),
158 _T("wxLongLong to long conversion loss of precision") );
160 return wx_truncate_cast(long, m_ll
);
163 #if wxABI_VERSION >= 20602
165 double ToDouble() const { return wx_truncate_cast(double, m_ll
); }
166 #endif // ABI >= 2.6.2
168 // don't provide implicit conversion to wxLongLong_t or we will have an
169 // ambiguity for all arithmetic operations
170 //operator wxLongLong_t() const { return m_ll; }
174 wxLongLongNative
operator+(const wxLongLongNative
& ll
) const
175 { return wxLongLongNative(m_ll
+ ll
.m_ll
); }
176 wxLongLongNative
& operator+=(const wxLongLongNative
& ll
)
177 { m_ll
+= ll
.m_ll
; return *this; }
179 wxLongLongNative
operator+(const wxLongLong_t ll
) const
180 { return wxLongLongNative(m_ll
+ ll
); }
181 wxLongLongNative
& operator+=(const wxLongLong_t ll
)
182 { m_ll
+= ll
; return *this; }
185 wxLongLongNative
& operator++()
186 { m_ll
++; return *this; }
189 wxLongLongNative
operator++(int)
190 { wxLongLongNative
value(*this); m_ll
++; return value
; }
193 wxLongLongNative
operator-() const
194 { return wxLongLongNative(-m_ll
); }
195 wxLongLongNative
& Negate() { m_ll
= -m_ll
; return *this; }
198 wxLongLongNative
operator-(const wxLongLongNative
& ll
) const
199 { return wxLongLongNative(m_ll
- ll
.m_ll
); }
200 wxLongLongNative
& operator-=(const wxLongLongNative
& ll
)
201 { m_ll
-= ll
.m_ll
; return *this; }
203 wxLongLongNative
operator-(const wxLongLong_t ll
) const
204 { return wxLongLongNative(m_ll
- ll
); }
205 wxLongLongNative
& operator-=(const wxLongLong_t ll
)
206 { m_ll
-= ll
; return *this; }
209 wxLongLongNative
& operator--()
210 { m_ll
--; return *this; }
213 wxLongLongNative
operator--(int)
214 { wxLongLongNative
value(*this); m_ll
--; return value
; }
218 wxLongLongNative
operator<<(int shift
) const
219 { return wxLongLongNative(m_ll
<< shift
); }
220 wxLongLongNative
& operator<<=(int shift
)
221 { m_ll
<<= shift
; return *this; }
224 wxLongLongNative
operator>>(int shift
) const
225 { return wxLongLongNative(m_ll
>> shift
); }
226 wxLongLongNative
& operator>>=(int shift
)
227 { m_ll
>>= shift
; return *this; }
230 wxLongLongNative
operator&(const wxLongLongNative
& ll
) const
231 { return wxLongLongNative(m_ll
& ll
.m_ll
); }
232 wxLongLongNative
& operator&=(const wxLongLongNative
& ll
)
233 { m_ll
&= ll
.m_ll
; return *this; }
235 wxLongLongNative
operator|(const wxLongLongNative
& ll
) const
236 { return wxLongLongNative(m_ll
| ll
.m_ll
); }
237 wxLongLongNative
& operator|=(const wxLongLongNative
& ll
)
238 { m_ll
|= ll
.m_ll
; return *this; }
240 wxLongLongNative
operator^(const wxLongLongNative
& ll
) const
241 { return wxLongLongNative(m_ll
^ ll
.m_ll
); }
242 wxLongLongNative
& operator^=(const wxLongLongNative
& ll
)
243 { m_ll
^= ll
.m_ll
; return *this; }
245 // multiplication/division
246 wxLongLongNative
operator*(const wxLongLongNative
& ll
) const
247 { return wxLongLongNative(m_ll
* ll
.m_ll
); }
248 wxLongLongNative
operator*(long l
) const
249 { return wxLongLongNative(m_ll
* l
); }
250 wxLongLongNative
& operator*=(const wxLongLongNative
& ll
)
251 { m_ll
*= ll
.m_ll
; return *this; }
252 wxLongLongNative
& operator*=(long l
)
253 { m_ll
*= l
; return *this; }
255 wxLongLongNative
operator/(const wxLongLongNative
& ll
) const
256 { return wxLongLongNative(m_ll
/ ll
.m_ll
); }
257 wxLongLongNative
operator/(long l
) const
258 { return wxLongLongNative(m_ll
/ l
); }
259 wxLongLongNative
& operator/=(const wxLongLongNative
& ll
)
260 { m_ll
/= ll
.m_ll
; return *this; }
261 wxLongLongNative
& operator/=(long l
)
262 { m_ll
/= l
; return *this; }
264 wxLongLongNative
operator%(const wxLongLongNative
& ll
) const
265 { return wxLongLongNative(m_ll
% ll
.m_ll
); }
266 wxLongLongNative
operator%(long l
) const
267 { return wxLongLongNative(m_ll
% l
); }
270 bool operator==(const wxLongLongNative
& ll
) const
271 { return m_ll
== ll
.m_ll
; }
272 bool operator==(long l
) const
273 { return m_ll
== l
; }
274 bool operator!=(const wxLongLongNative
& ll
) const
275 { return m_ll
!= ll
.m_ll
; }
276 bool operator!=(long l
) const
277 { return m_ll
!= l
; }
278 bool operator<(const wxLongLongNative
& ll
) const
279 { return m_ll
< ll
.m_ll
; }
280 bool operator<(long l
) const
282 bool operator>(const wxLongLongNative
& ll
) const
283 { return m_ll
> ll
.m_ll
; }
284 bool operator>(long l
) const
286 bool operator<=(const wxLongLongNative
& ll
) const
287 { return m_ll
<= ll
.m_ll
; }
288 bool operator<=(long l
) const
289 { return m_ll
<= l
; }
290 bool operator>=(const wxLongLongNative
& ll
) const
291 { return m_ll
>= ll
.m_ll
; }
292 bool operator>=(long l
) const
293 { return m_ll
>= l
; }
297 // return the string representation of this number
298 wxString
ToString() const;
300 // conversion to byte array: returns a pointer to static buffer!
301 void *asArray() const;
303 #if wxUSE_STD_IOSTREAM
305 friend WXDLLIMPEXP_BASE
306 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongNative
&);
309 friend WXDLLIMPEXP_BASE
310 wxString
& operator<<(wxString
&, const wxLongLongNative
&);
317 class WXDLLIMPEXP_BASE wxULongLongNative
321 // default ctor initializes to 0
322 wxULongLongNative() : m_ll(0) { }
324 wxULongLongNative(wxULongLong_t ll
) : m_ll(ll
) { }
326 wxULongLongNative(unsigned long hi
, unsigned long lo
) : m_ll(0)
328 // assign first to avoid precision loss!
329 m_ll
= ((wxULongLong_t
) hi
) << 32;
330 m_ll
|= (wxULongLong_t
) lo
;
333 // default copy ctor is ok
337 // assignment operators
338 // from native 64 bit integer
339 wxULongLongNative
& operator=(wxULongLong_t ll
)
340 { m_ll
= ll
; return *this; }
342 // assignment operators from wxULongLongNative is ok
346 unsigned long GetHi() const
347 { return wx_truncate_cast(unsigned long, m_ll
>> 32); }
349 unsigned long GetLo() const
350 { return wx_truncate_cast(unsigned long, m_ll
); }
352 // convert to native ulong long
353 wxULongLong_t
GetValue() const { return m_ll
; }
355 // convert to ulong with range checking in the debug mode (only!)
356 unsigned long ToULong() const
358 wxASSERT_MSG( m_ll
<= LONG_MAX
,
359 _T("wxULongLong to long conversion loss of precision") );
361 return wx_truncate_cast(unsigned long, m_ll
);
366 wxULongLongNative
operator+(const wxULongLongNative
& ll
) const
367 { return wxULongLongNative(m_ll
+ ll
.m_ll
); }
368 wxULongLongNative
& operator+=(const wxULongLongNative
& ll
)
369 { m_ll
+= ll
.m_ll
; return *this; }
371 wxULongLongNative
operator+(const wxULongLong_t ll
) const
372 { return wxULongLongNative(m_ll
+ ll
); }
373 wxULongLongNative
& operator+=(const wxULongLong_t ll
)
374 { m_ll
+= ll
; return *this; }
377 wxULongLongNative
& operator++()
378 { m_ll
++; return *this; }
381 wxULongLongNative
operator++(int)
382 { wxULongLongNative
value(*this); m_ll
++; return value
; }
385 wxULongLongNative
operator-(const wxULongLongNative
& ll
) const
386 { return wxULongLongNative(m_ll
- ll
.m_ll
); }
387 wxULongLongNative
& operator-=(const wxULongLongNative
& ll
)
388 { m_ll
-= ll
.m_ll
; return *this; }
390 wxULongLongNative
operator-(const wxULongLong_t ll
) const
391 { return wxULongLongNative(m_ll
- ll
); }
392 wxULongLongNative
& operator-=(const wxULongLong_t ll
)
393 { m_ll
-= ll
; return *this; }
396 wxULongLongNative
& operator--()
397 { m_ll
--; return *this; }
400 wxULongLongNative
operator--(int)
401 { wxULongLongNative
value(*this); m_ll
--; return value
; }
405 wxULongLongNative
operator<<(int shift
) const
406 { return wxULongLongNative(m_ll
<< shift
); }
407 wxULongLongNative
& operator<<=(int shift
)
408 { m_ll
<<= shift
; return *this; }
411 wxULongLongNative
operator>>(int shift
) const
412 { return wxULongLongNative(m_ll
>> shift
); }
413 wxULongLongNative
& operator>>=(int shift
)
414 { m_ll
>>= shift
; return *this; }
417 wxULongLongNative
operator&(const wxULongLongNative
& ll
) const
418 { return wxULongLongNative(m_ll
& ll
.m_ll
); }
419 wxULongLongNative
& operator&=(const wxULongLongNative
& ll
)
420 { m_ll
&= ll
.m_ll
; return *this; }
422 wxULongLongNative
operator|(const wxULongLongNative
& ll
) const
423 { return wxULongLongNative(m_ll
| ll
.m_ll
); }
424 wxULongLongNative
& operator|=(const wxULongLongNative
& ll
)
425 { m_ll
|= ll
.m_ll
; return *this; }
427 wxULongLongNative
operator^(const wxULongLongNative
& ll
) const
428 { return wxULongLongNative(m_ll
^ ll
.m_ll
); }
429 wxULongLongNative
& operator^=(const wxULongLongNative
& ll
)
430 { m_ll
^= ll
.m_ll
; return *this; }
432 // multiplication/division
433 wxULongLongNative
operator*(const wxULongLongNative
& ll
) const
434 { return wxULongLongNative(m_ll
* ll
.m_ll
); }
435 wxULongLongNative
operator*(unsigned long l
) const
436 { return wxULongLongNative(m_ll
* l
); }
437 wxULongLongNative
& operator*=(const wxULongLongNative
& ll
)
438 { m_ll
*= ll
.m_ll
; return *this; }
439 wxULongLongNative
& operator*=(unsigned long l
)
440 { m_ll
*= l
; return *this; }
442 wxULongLongNative
operator/(const wxULongLongNative
& ll
) const
443 { return wxULongLongNative(m_ll
/ ll
.m_ll
); }
444 wxULongLongNative
operator/(unsigned long l
) const
445 { return wxULongLongNative(m_ll
/ l
); }
446 wxULongLongNative
& operator/=(const wxULongLongNative
& ll
)
447 { m_ll
/= ll
.m_ll
; return *this; }
448 wxULongLongNative
& operator/=(unsigned long l
)
449 { m_ll
/= l
; return *this; }
451 wxULongLongNative
operator%(const wxULongLongNative
& ll
) const
452 { return wxULongLongNative(m_ll
% ll
.m_ll
); }
453 wxULongLongNative
operator%(unsigned long l
) const
454 { return wxULongLongNative(m_ll
% l
); }
457 bool operator==(const wxULongLongNative
& ll
) const
458 { return m_ll
== ll
.m_ll
; }
459 bool operator==(unsigned long l
) const
460 { return m_ll
== l
; }
461 bool operator!=(const wxULongLongNative
& ll
) const
462 { return m_ll
!= ll
.m_ll
; }
463 bool operator!=(unsigned long l
) const
464 { return m_ll
!= l
; }
465 bool operator<(const wxULongLongNative
& ll
) const
466 { return m_ll
< ll
.m_ll
; }
467 bool operator<(unsigned long l
) const
469 bool operator>(const wxULongLongNative
& ll
) const
470 { return m_ll
> ll
.m_ll
; }
471 bool operator>(unsigned long l
) const
473 bool operator<=(const wxULongLongNative
& ll
) const
474 { return m_ll
<= ll
.m_ll
; }
475 bool operator<=(unsigned long l
) const
476 { return m_ll
<= l
; }
477 bool operator>=(const wxULongLongNative
& ll
) const
478 { return m_ll
>= ll
.m_ll
; }
479 bool operator>=(unsigned long l
) const
480 { return m_ll
>= l
; }
484 // return the string representation of this number
485 wxString
ToString() const;
487 // conversion to byte array: returns a pointer to static buffer!
488 void *asArray() const;
490 #if wxUSE_STD_IOSTREAM
492 friend WXDLLIMPEXP_BASE
493 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongNative
&);
496 friend WXDLLIMPEXP_BASE
497 wxString
& operator<<(wxString
&, const wxULongLongNative
&);
503 #endif // wxUSE_LONGLONG_NATIVE
505 #if wxUSE_LONGLONG_WX
507 class WXDLLIMPEXP_BASE wxLongLongWx
511 // default ctor initializes to 0
516 #ifdef wxLONGLONG_TEST_MODE
520 #endif // wxLONGLONG_TEST_MODE
523 wxLongLongWx(long l
) { *this = l
; }
525 wxLongLongWx(long hi
, unsigned long lo
)
530 #ifdef wxLONGLONG_TEST_MODE
536 #endif // wxLONGLONG_TEST_MODE
539 // default copy ctor is ok in both cases
543 // assignment operators
545 wxLongLongWx
& operator=(long l
)
548 m_hi
= (l
< 0 ? -1l : 0l);
550 #ifdef wxLONGLONG_TEST_MODE
554 #endif // wxLONGLONG_TEST_MODE
559 wxLongLongWx
& Assign(double d
);
560 // can't have assignment operator from 2 longs
564 long GetHi() const { return m_hi
; }
566 unsigned long GetLo() const { return m_lo
; }
568 // get absolute value
569 wxLongLongWx
Abs() const { return wxLongLongWx(*this).Abs(); }
575 #ifdef wxLONGLONG_TEST_MODE
580 #endif // wxLONGLONG_TEST_MODE
585 // convert to long with range checking in the debug mode (only!)
588 wxASSERT_MSG( (m_hi
== 0l) || (m_hi
== -1l),
589 _T("wxLongLong to long conversion loss of precision") );
594 #if wxABI_VERSION >= 20602
596 double ToDouble() const;
597 #endif // ABI >= 2.6.2
601 wxLongLongWx
operator+(const wxLongLongWx
& ll
) const;
602 wxLongLongWx
& operator+=(const wxLongLongWx
& ll
);
603 wxLongLongWx
operator+(long l
) const;
604 wxLongLongWx
& operator+=(long l
);
606 // pre increment operator
607 wxLongLongWx
& operator++();
609 // post increment operator
610 wxLongLongWx
& operator++(int) { return ++(*this); }
613 wxLongLongWx
operator-() const;
614 wxLongLongWx
& Negate();
617 wxLongLongWx
operator-(const wxLongLongWx
& ll
) const;
618 wxLongLongWx
& operator-=(const wxLongLongWx
& ll
);
620 // pre decrement operator
621 wxLongLongWx
& operator--();
623 // post decrement operator
624 wxLongLongWx
& operator--(int) { return --(*this); }
628 wxLongLongWx
operator<<(int shift
) const;
629 wxLongLongWx
& operator<<=(int shift
);
632 wxLongLongWx
operator>>(int shift
) const;
633 wxLongLongWx
& operator>>=(int shift
);
636 wxLongLongWx
operator&(const wxLongLongWx
& ll
) const;
637 wxLongLongWx
& operator&=(const wxLongLongWx
& ll
);
638 wxLongLongWx
operator|(const wxLongLongWx
& ll
) const;
639 wxLongLongWx
& operator|=(const wxLongLongWx
& ll
);
640 wxLongLongWx
operator^(const wxLongLongWx
& ll
) const;
641 wxLongLongWx
& operator^=(const wxLongLongWx
& ll
);
642 wxLongLongWx
operator~() const;
645 bool operator==(const wxLongLongWx
& ll
) const
646 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
647 #if wxUSE_LONGLONG_NATIVE
648 bool operator==(const wxLongLongNative
& ll
) const
649 { return m_lo
== ll
.GetLo() && m_hi
== ll
.GetHi(); }
651 bool operator!=(const wxLongLongWx
& ll
) const
652 { return !(*this == ll
); }
653 bool operator<(const wxLongLongWx
& ll
) const;
654 bool operator>(const wxLongLongWx
& ll
) const;
655 bool operator<=(const wxLongLongWx
& ll
) const
656 { return *this < ll
|| *this == ll
; }
657 bool operator>=(const wxLongLongWx
& ll
) const
658 { return *this > ll
|| *this == ll
; }
660 bool operator<(long l
) const { return *this < wxLongLongWx(l
); }
661 bool operator>(long l
) const { return *this > wxLongLongWx(l
); }
662 bool operator==(long l
) const
664 return l
>= 0 ? (m_hi
== 0 && m_lo
== (unsigned long)l
)
665 : (m_hi
== -1 && m_lo
== (unsigned long)l
);
668 bool operator<=(long l
) const { return *this < l
|| *this == l
; }
669 bool operator>=(long l
) const { return *this > l
|| *this == l
; }
672 wxLongLongWx
operator*(const wxLongLongWx
& ll
) const;
673 wxLongLongWx
& operator*=(const wxLongLongWx
& ll
);
676 wxLongLongWx
operator/(const wxLongLongWx
& ll
) const;
677 wxLongLongWx
& operator/=(const wxLongLongWx
& ll
);
679 wxLongLongWx
operator%(const wxLongLongWx
& ll
) const;
681 void Divide(const wxLongLongWx
& divisor
,
682 wxLongLongWx
& quotient
,
683 wxLongLongWx
& remainder
) const;
687 // return the string representation of this number
688 wxString
ToString() const;
690 void *asArray() const;
692 #if wxUSE_STD_IOSTREAM
693 friend WXDLLIMPEXP_BASE
694 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxLongLongWx
&);
695 #endif // wxUSE_STD_IOSTREAM
697 friend WXDLLIMPEXP_BASE
698 wxString
& operator<<(wxString
&, const wxLongLongWx
&);
701 // long is at least 32 bits, so represent our 64bit number as 2 longs
703 long m_hi
; // signed bit is in the high part
706 #ifdef wxLONGLONG_TEST_MODE
709 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
713 #endif // wxLONGLONG_TEST_MODE
717 class WXDLLIMPEXP_BASE wxULongLongWx
721 // default ctor initializes to 0
726 #ifdef wxLONGLONG_TEST_MODE
730 #endif // wxLONGLONG_TEST_MODE
733 wxULongLongWx(unsigned long l
) { *this = l
; }
735 wxULongLongWx(unsigned long hi
, unsigned long lo
)
740 #ifdef wxLONGLONG_TEST_MODE
746 #endif // wxLONGLONG_TEST_MODE
749 // from signed to unsigned
750 wxULongLongWx(wxLongLongWx ll
)
752 wxASSERT(ll
.GetHi() >= 0);
753 m_hi
= (unsigned long)ll
.GetHi();
757 // default copy ctor is ok in both cases
761 // assignment operators
763 wxULongLongWx
& operator=(unsigned long l
)
768 #ifdef wxLONGLONG_TEST_MODE
772 #endif // wxLONGLONG_TEST_MODE
777 // can't have assignment operator from 2 longs
781 unsigned long GetHi() const { return m_hi
; }
783 unsigned long GetLo() const { return m_lo
; }
785 // convert to long with range checking in the debug mode (only!)
786 unsigned long ToULong() const
788 wxASSERT_MSG( m_hi
== 0ul,
789 _T("wxULongLong to long conversion loss of precision") );
791 return (unsigned long)m_lo
;
796 wxULongLongWx
operator+(const wxULongLongWx
& ll
) const;
797 wxULongLongWx
& operator+=(const wxULongLongWx
& ll
);
798 wxULongLongWx
operator+(unsigned long l
) const;
799 wxULongLongWx
& operator+=(unsigned long l
);
801 // pre increment operator
802 wxULongLongWx
& operator++();
804 // post increment operator
805 wxULongLongWx
& operator++(int) { return ++(*this); }
808 wxLongLongWx
operator-(const wxULongLongWx
& ll
) const;
809 wxULongLongWx
& operator-=(const wxULongLongWx
& ll
);
811 // pre decrement operator
812 wxULongLongWx
& operator--();
814 // post decrement operator
815 wxULongLongWx
& operator--(int) { return --(*this); }
819 wxULongLongWx
operator<<(int shift
) const;
820 wxULongLongWx
& operator<<=(int shift
);
823 wxULongLongWx
operator>>(int shift
) const;
824 wxULongLongWx
& operator>>=(int shift
);
827 wxULongLongWx
operator&(const wxULongLongWx
& ll
) const;
828 wxULongLongWx
& operator&=(const wxULongLongWx
& ll
);
829 wxULongLongWx
operator|(const wxULongLongWx
& ll
) const;
830 wxULongLongWx
& operator|=(const wxULongLongWx
& ll
);
831 wxULongLongWx
operator^(const wxULongLongWx
& ll
) const;
832 wxULongLongWx
& operator^=(const wxULongLongWx
& ll
);
833 wxULongLongWx
operator~() const;
836 bool operator==(const wxULongLongWx
& ll
) const
837 { return m_lo
== ll
.m_lo
&& m_hi
== ll
.m_hi
; }
838 bool operator!=(const wxULongLongWx
& ll
) const
839 { return !(*this == ll
); }
840 bool operator<(const wxULongLongWx
& ll
) const;
841 bool operator>(const wxULongLongWx
& ll
) const;
842 bool operator<=(const wxULongLongWx
& ll
) const
843 { return *this < ll
|| *this == ll
; }
844 bool operator>=(const wxULongLongWx
& ll
) const
845 { return *this > ll
|| *this == ll
; }
847 bool operator<(unsigned long l
) const { return *this < wxULongLongWx(l
); }
848 bool operator>(unsigned long l
) const { return *this > wxULongLongWx(l
); }
849 bool operator==(unsigned long l
) const
851 return (m_hi
== 0 && m_lo
== (unsigned long)l
);
854 bool operator<=(unsigned long l
) const { return *this < l
|| *this == l
; }
855 bool operator>=(unsigned long l
) const { return *this > l
|| *this == l
; }
858 wxULongLongWx
operator*(const wxULongLongWx
& ll
) const;
859 wxULongLongWx
& operator*=(const wxULongLongWx
& ll
);
862 wxULongLongWx
operator/(const wxULongLongWx
& ll
) const;
863 wxULongLongWx
& operator/=(const wxULongLongWx
& ll
);
865 wxULongLongWx
operator%(const wxULongLongWx
& ll
) const;
867 void Divide(const wxULongLongWx
& divisor
,
868 wxULongLongWx
& quotient
,
869 wxULongLongWx
& remainder
) const;
873 // return the string representation of this number
874 wxString
ToString() const;
876 void *asArray() const;
878 #if wxUSE_STD_IOSTREAM
879 friend WXDLLIMPEXP_BASE
880 wxSTD ostream
& operator<<(wxSTD ostream
&, const wxULongLongWx
&);
881 #endif // wxUSE_STD_IOSTREAM
883 friend WXDLLIMPEXP_BASE
884 wxString
& operator<<(wxString
&, const wxULongLongWx
&);
887 // long is at least 32 bits, so represent our 64bit number as 2 longs
892 #ifdef wxLONGLONG_TEST_MODE
895 wxASSERT( (m_ll
>> 32) == m_hi
&& (unsigned long)m_ll
== m_lo
);
899 #endif // wxLONGLONG_TEST_MODE
902 #endif // wxUSE_LONGLONG_WX
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 inline bool operator<(long l
, const wxLongLong
& ll
) { return ll
> l
; }
909 inline bool operator>(long l
, const wxLongLong
& ll
) { return ll
< l
; }
910 inline bool operator<=(long l
, const wxLongLong
& ll
) { return ll
>= l
; }
911 inline bool operator>=(long l
, const wxLongLong
& ll
) { return ll
<= l
; }
912 inline bool operator==(long l
, const wxLongLong
& ll
) { return ll
== l
; }
913 inline bool operator!=(long l
, const wxLongLong
& ll
) { return ll
!= l
; }
915 inline wxLongLong
operator+(long l
, const wxLongLong
& ll
) { return ll
+ l
; }
916 inline wxLongLong
operator-(long l
, const wxLongLong
& ll
)
918 return wxLongLong(l
) - ll
;
921 inline bool operator<(unsigned long l
, const wxULongLong
& ull
) { return ull
> l
; }
922 inline bool operator>(unsigned long l
, const wxULongLong
& ull
) { return ull
< l
; }
923 inline bool operator<=(unsigned long l
, const wxULongLong
& ull
) { return ull
>= l
; }
924 inline bool operator>=(unsigned long l
, const wxULongLong
& ull
) { return ull
<= l
; }
925 inline bool operator==(unsigned long l
, const wxULongLong
& ull
) { return ull
== l
; }
926 inline bool operator!=(unsigned long l
, const wxULongLong
& ull
) { return ull
!= l
; }
928 inline wxULongLong
operator+(unsigned long l
, const wxULongLong
& ull
) { return ull
+ l
; }
930 inline wxLongLong
operator-(unsigned long l
, const wxULongLong
& ull
)
932 wxULongLong ret
= wxULongLong(l
) - ull
;
933 return wxLongLong((long)ret
.GetHi(),ret
.GetLo());
936 #endif // _WX_LONGLONG_H