// 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))
{
// all responsibility for using this code.
// init everything
- wxLongLongWx dividend = *this,
- divisor = divisorIn;
+ wxULongLongWx dividend, divisor, remainder;
quotient = 0l;
remainder = 0l;
// 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
size_t nBits = 64u;
wxLongLongWx d;
- #define IS_MSB_SET(ll) ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
-
while ( remainder < divisor )
{
remainder <<= 1;
}
}
+ remainderIO = remainder;
+
// adjust signs
if ( negRemainder )
{
- remainder = -remainder;
+ remainderIO = -remainderIO;
}
if ( negQuotient )
size_t nBits = 64u;
wxULongLongWx d;
- #define IS_MSB_SET(ll) ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
-
while ( remainder < divisor )
{
remainder <<= 1;