|
|
@@ -30,12 +30,12 @@ namespace math { namespace detail {
|
|
|
}
|
|
|
#undef IMPL_COMPARE
|
|
|
|
|
|
- void add(data_type & rhs, data_type const & lhs) {
|
|
|
- rhs.resize(std::max(rhs.size(), lhs.size())+1);
|
|
|
+ void add(data_type & rhs, data_type const & lhs, size_t offset) {
|
|
|
+ rhs.resize(std::max(rhs.size(), lhs.size()+offset)+1);
|
|
|
auto const lbnd = lhs.size(), ubnd = rhs.size() - 1;
|
|
|
// Add
|
|
|
for (size_t i = 0; i < lbnd; ++i) {
|
|
|
- rhs[i] += lhs[i];
|
|
|
+ rhs[i+offset] += lhs[i];
|
|
|
}
|
|
|
// Carry
|
|
|
for (size_t i = 0; i < ubnd; ++i) {
|
|
|
@@ -47,11 +47,11 @@ namespace math { namespace detail {
|
|
|
if (rhs[ubnd] == 0) { rhs.pop_back(); }
|
|
|
}
|
|
|
|
|
|
- void subtract_nounderflow(data_type & rhs, data_type const & lhs) {
|
|
|
+ void subtract_nounderflow(data_type & rhs, data_type const & lhs, size_t offset) {
|
|
|
size_t const rbnd = rhs.size(), lbnd = lhs.size();
|
|
|
// Subtract
|
|
|
for (size_t i = 0; i < lbnd; ++i) {
|
|
|
- rhs[i] -= lhs[i];
|
|
|
+ rhs[i+offset] -= lhs[i];
|
|
|
}
|
|
|
// Borrow
|
|
|
for (size_t i = 0; i < rbnd; ++i) {
|
|
|
@@ -121,11 +121,11 @@ namespace math { namespace detail {
|
|
|
auto const diff = std::max(1UL, digits(remainder) - dig) - 1;
|
|
|
auto const shift = diff / SEG_DIGITS;
|
|
|
auto const ipow = diff - (shift * SEG_DIGITS);
|
|
|
- data_type step{shift10({1}, powers[ipow], shift)};
|
|
|
- data_type value{shift10(divisor, powers[ipow], shift)};
|
|
|
+ data_type step{shift10({1}, powers[ipow], 0)};
|
|
|
+ data_type value{shift10(divisor, powers[ipow], 0)};
|
|
|
do {
|
|
|
- subtract_nounderflow(remainder, value);
|
|
|
- add(accum, step);
|
|
|
+ subtract_nounderflow(remainder, value, shift);
|
|
|
+ add(accum, step, shift);
|
|
|
} while (compare(remainder, value) >= 0);
|
|
|
} while (compare(remainder, divisor) >= 0);
|
|
|
return accum;
|