fix for wxLongLong division test (patch 1233771)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-07-28 21:49:26 +00:00
parent 93c96bab3d
commit 6984e41478

View File

@@ -779,9 +779,11 @@ wxULongLongWx& wxULongLongWx::operator*=(const wxULongLongWx& ll)
// division // division
#define IS_MSB_SET(ll) ((ll.GetHi()) & (1 << (8*sizeof(long) - 1)))
void wxLongLongWx::Divide(const wxLongLongWx& divisorIn, void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
wxLongLongWx& quotient, wxLongLongWx& quotient,
wxLongLongWx& remainder) const wxLongLongWx& remainderIO) const
{ {
if ((divisorIn.m_lo == 0) && (divisorIn.m_hi == 0)) 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. // all responsibility for using this code.
// init everything // init everything
wxLongLongWx dividend = *this, wxULongLongWx dividend, divisor, remainder;
divisor = divisorIn;
quotient = 0l; quotient = 0l;
remainder = 0l; remainder = 0l;
@@ -819,17 +820,21 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
// dividend = quotient*divisor + remainder // dividend = quotient*divisor + remainder
// //
// with 0 <= abs(remainder) < abs(divisor) // with 0 <= abs(remainder) < abs(divisor)
bool negRemainder = dividend.m_hi < 0; bool negRemainder = GetHi() < 0;
bool negQuotient = false; // assume positive bool negQuotient = false; // assume positive
if ( dividend.m_hi < 0 ) if ( GetHi() < 0 )
{ {
negQuotient = !negQuotient; negQuotient = !negQuotient;
dividend = -dividend; dividend = -*this;
} else {
dividend = *this;
} }
if ( divisor.m_hi < 0 ) if ( divisorIn.GetHi() < 0 )
{ {
negQuotient = !negQuotient; negQuotient = !negQuotient;
divisor = -divisor; divisor = -divisorIn;
} else {
divisor = divisorIn;
} }
// check for some particular cases // check for some particular cases
@@ -847,8 +852,6 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
size_t nBits = 64u; size_t nBits = 64u;
wxLongLongWx d; wxLongLongWx d;
#define IS_MSB_SET(ll) ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
while ( remainder < divisor ) while ( remainder < divisor )
{ {
remainder <<= 1; remainder <<= 1;
@@ -888,10 +891,12 @@ void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
} }
} }
remainderIO = remainder;
// adjust signs // adjust signs
if ( negRemainder ) if ( negRemainder )
{ {
remainder = -remainder; remainderIO = -remainderIO;
} }
if ( negQuotient ) if ( negQuotient )
@@ -947,8 +952,6 @@ void wxULongLongWx::Divide(const wxULongLongWx& divisorIn,
size_t nBits = 64u; size_t nBits = 64u;
wxULongLongWx d; wxULongLongWx d;
#define IS_MSB_SET(ll) ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
while ( remainder < divisor ) while ( remainder < divisor )
{ {
remainder <<= 1; remainder <<= 1;