+ //
+ // code inspired by the snippet at
+ // http://www.bearcave.com/software/divide.htm
+ //
+ // Copyright notice:
+ //
+ // Use of this program, for any purpose, is granted the author, Ian
+ // Kaplan, as long as this copyright notice is included in the source
+ // code or any source code derived from this program. The user assumes
+ // all responsibility for using this code.
+
+ // init everything
+ wxLongLongWx dividend = *this,
+ divisor = divisorIn;
+
+ quotient = 0l;
+ remainder = 0l;
+
+ // always do unsigned division and adjust the signs later: in C integer
+ // division, the sign of the remainder is the same as the sign of the
+ // dividend, while the sign of the quotient is the product of the signs of
+ // the dividend and divisor. Of course, we also always have
+ //
+ // dividend = quotient*divisor + remainder
+ //
+ // with 0 <= abs(remainder) < abs(divisor)
+ bool negRemainder = dividend.m_hi < 0;
+ bool negQuotient = FALSE; // assume positive
+ if ( dividend.m_hi < 0 )
+ {
+ negQuotient = !negQuotient;
+ dividend = -dividend;
+ }
+ if ( divisor.m_hi < 0 )
+ {
+ negQuotient = !negQuotient;
+ divisor = -divisor;
+ }