]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/longlong.cpp
use ifdef, not if, to test for HAVE_WCSRTOMBS
[wxWidgets.git] / src / common / longlong.cpp
index 2e589fa72324eb58dfea9e43ad3681137f5229d5..4646ce0d7b29d3b648eb51f4b17313ad3e97051c 100644 (file)
@@ -35,6 +35,8 @@
 #include <memory.h>     // for memset()
 #endif
 
+#include "wx/ioswrap.h"
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -751,7 +753,7 @@ wxULongLongWx& wxULongLongWx::operator*=(const wxULongLongWx& ll)
     m_hi = m_lo = 0;
 
 #ifdef wxLONGLONG_TEST_MODE
-    unsigned wxLongLong_t llOld = m_ll;
+    wxULongLong_t llOld = m_ll;
     m_ll = 0;
 #endif // wxLONGLONG_TEST_MODE
 
@@ -777,9 +779,11 @@ wxULongLongWx& wxULongLongWx::operator*=(const wxULongLongWx& ll)
 
 // division
 
+#define IS_MSB_SET(ll)  ((ll.GetHi()) & (1 << (8*sizeof(long) - 1)))
+
 void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
                           wxLongLongWx& quotient,
-                          wxLongLongWx& remainder) const
+                          wxLongLongWx& remainderIO) const
 {
     if ((divisorIn.m_lo == 0) && (divisorIn.m_hi == 0))
     {
@@ -803,8 +807,7 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
     //     all responsibility for using this code.
 
     // init everything
-    wxLongLongWx dividend = *this,
-                 divisor = divisorIn;
+    wxULongLongWx dividend, divisor, remainder;
 
     quotient = 0l;
     remainder = 0l;
@@ -817,17 +820,21 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
     //      dividend = quotient*divisor + remainder
     //
     // with 0 <= abs(remainder) < abs(divisor)
-    bool negRemainder = dividend.m_hi < 0;
+    bool negRemainder = GetHi() < 0;
     bool negQuotient = false;   // assume positive
-    if ( dividend.m_hi < 0 )
+    if ( GetHi() < 0 )
     {
         negQuotient = !negQuotient;
-        dividend = -dividend;
+        dividend = -*this;
+    } else {
+        dividend = *this;
     }
-    if ( divisor.m_hi < 0 )
+    if ( divisorIn.GetHi() < 0 )
     {
         negQuotient = !negQuotient;
-        divisor = -divisor;
+        divisor = -divisorIn;
+    } else {
+        divisor = divisorIn;
     }
 
     // check for some particular cases
@@ -845,8 +852,6 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
         size_t nBits = 64u;
         wxLongLongWx d;
 
-        #define IS_MSB_SET(ll)  ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
-
         while ( remainder < divisor )
         {
             remainder <<= 1;
@@ -886,10 +891,12 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
         }
     }
 
+    remainderIO = remainder;
+
     // adjust signs
     if ( negRemainder )
     {
-        remainder = -remainder;
+        remainderIO = -remainderIO;
     }
 
     if ( negQuotient )
@@ -945,8 +952,6 @@ void wxULongLongWx::Divide(const wxULongLongWx& divisorIn,
         size_t nBits = 64u;
         wxULongLongWx d;
 
-        #define IS_MSB_SET(ll)  ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
-
         while ( remainder < divisor )
         {
             remainder <<= 1;
@@ -1092,21 +1097,24 @@ void *wxULongLongWx::asArray(void) const
                                                                      \
         name ll = *this;                                             \
                                                                      \
-        bool neg;                                                    \
-        if ( ll < 0 )                                                \
+        bool neg = ll < 0;                                           \
+        if ( neg )                                                   \
         {                                                            \
-            ll.Negate();                                             \
-            neg = true;                                              \
+            while ( ll != 0 )                                        \
+            {                                                        \
+                long digit = (ll % 10).ToLong();                     \
+                result.Prepend((wxChar)(_T('0') - digit));           \
+                ll /= 10;                                            \
+            }                                                        \
         }                                                            \
         else                                                         \
         {                                                            \
-            neg = false;                                             \
-        }                                                            \
-                                                                     \
-        while ( ll != 0 )                                            \
-        {                                                            \
-            result.Prepend((wxChar)(_T('0') + (ll % 10).ToLong()));  \
-            ll /= 10;                                                \
+            while ( ll != 0 )                                        \
+            {                                                        \
+                long digit = (ll % 10).ToLong();                     \
+                result.Prepend((wxChar)(_T('0') + digit));           \
+                ll /= 10;                                            \
+            }                                                        \
         }                                                            \
                                                                      \
         if ( result.empty() )                                        \
@@ -1150,11 +1158,13 @@ void *wxULongLongWx::asArray(void) const
 #if wxUSE_STD_IOSTREAM
 
 // input/output
+WXDLLIMPEXP_BASE
 wxSTD ostream& operator<< (wxSTD ostream& o, const wxLongLong& ll)
 {
     return o << ll.ToString();
 }
 
+WXDLLIMPEXP_BASE
 wxSTD ostream& operator<< (wxSTD ostream& o, const wxULongLong& ll)
 {
     return o << ll.ToString();