+ // VZ: I'm writing this in a hurry and it's surely not the fastest way to
+ // do this - any improvements are more than welcome
+
+ // the algorithm: first find N such that 2^N * divisor is less than us,
+ // then substract divisor from *this - 2^N * divisor as many times as
+ // possible
+
+ wxLongLongWx prev = divisor;
+ remainder = *this;
+
+ quotient = 1l;
+
+ for ( wxLongLongWx tmp = divisor; tmp < remainder; )
+ {
+ prev = tmp;
+
+ tmp <<= 1;
+
+ if ( tmp < 0 )
+ {
+ // shifted too far
+ break;
+ }
+
+ quotient <<= 1;
+ }
+
+ while ( remainder >= prev )
+ {
+ remainder -= divisor;
+ quotient++;
+ }
+
+ // remainder should be in this range at the end
+ wxASSERT_MSG( (0l <= remainder) && (remainder < divisor.Abs()),
+ _T("logic error in wxLongLong division") );
+}
+
+wxLongLongWx wxLongLongWx::operator/(const wxLongLongWx& ll) const
+{
+ wxLongLongWx quotient, remainder;
+
+ Divide(ll, quotient, remainder);
+
+ return quotient;
+}
+
+wxLongLongWx& wxLongLongWx::operator/=(const wxLongLongWx& ll)
+{
+ wxLongLongWx quotient, remainder;
+
+ Divide(ll, quotient, remainder);
+
+ return *this = quotient;