From 6984e4147875396b257450ff793c20c2eb0e16a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Jul 2005 21:49:26 +0000 Subject: [PATCH] fix for wxLongLong division test (patch 1233771) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/longlong.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/common/longlong.cpp b/src/common/longlong.cpp index 9334dcc3f4..4646ce0d7b 100644 --- a/src/common/longlong.cpp +++ b/src/common/longlong.cpp @@ -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; -- 2.45.2