]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for wxLongLong division test (patch 1233771)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Jul 2005 21:49:26 +0000 (21:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Jul 2005 21:49:26 +0000 (21:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/longlong.cpp

index 9334dcc3f478e2c0c80987423337e63326d5847b..4646ce0d7b29d3b648eb51f4b17313ad3e97051c 100644 (file)
@@ -779,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))
     {
@@ -805,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;
@@ -819,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
@@ -847,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;
@@ -888,10 +891,12 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
         }
     }
 
+    remainderIO = remainder;
+
     // adjust signs
     if ( negRemainder )
     {
-        remainder = -remainder;
+        remainderIO = -remainderIO;
     }
 
     if ( negQuotient )
@@ -947,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;