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
#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;