#include <memory.h> // for memset()
#endif
+#include "wx/ioswrap.h"
+
// ============================================================================
// implementation
// ============================================================================
m_hi = m_lo = 0;
#ifdef wxLONGLONG_TEST_MODE
- unsigned wxLongLong_t llOld = m_ll;
+ wxULongLong_t llOld = m_ll;
m_ll = 0;
#endif // wxLONGLONG_TEST_MODE
// 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;
\
name ll = *this; \
\
- bool neg; \
- if ( ll < 0 ) \
+ bool neg = ll < 0; \
+ if ( neg ) \
{ \
- ll.Negate(); \
- neg = true; \
+ while ( ll != 0 ) \
+ { \
+ long digit = (ll % 10).ToLong(); \
+ result.Prepend((wxChar)(_T('0') - digit)); \
+ ll /= 10; \
+ } \
} \
else \
{ \
- neg = false; \
- } \
- \
- while ( ll != 0 ) \
- { \
- result.Prepend((wxChar)(_T('0') + (ll % 10).ToLong())); \
- ll /= 10; \
+ while ( ll != 0 ) \
+ { \
+ long digit = (ll % 10).ToLong(); \
+ result.Prepend((wxChar)(_T('0') + digit)); \
+ ll /= 10; \
+ } \
} \
\
if ( result.empty() ) \