|
|
@@ -72,20 +72,21 @@ namespace math { namespace detail {
|
|
|
if (rhs[rbnd-1] == 0 && rbnd > 1) { rhs.pop_back(); }
|
|
|
}
|
|
|
|
|
|
- void multiply(data_type & rhs, data_type const & lhs) {
|
|
|
+ void multiply(data_type & rhs, data_type const & lhs, size_t offset) {
|
|
|
size_t const rbnd = rhs.size(), lbnd = lhs.size();
|
|
|
size_t const ubnd = rbnd + lbnd;
|
|
|
rhs.resize(ubnd);
|
|
|
// Multiply
|
|
|
for (size_t i = rbnd; i > 0; --i) {
|
|
|
int32_t const value = rhs[i-1];
|
|
|
- for (size_t j = lbnd; j > 0; --j) {
|
|
|
+ for (size_t j = lbnd; j > offset; --j) {
|
|
|
// Max input 999,999,999
|
|
|
// Max output 999,999,998,000,000,001
|
|
|
int64_t product = int64_t(value) * lhs[j-1];
|
|
|
int64_t overflow = product / OVER_SEG;
|
|
|
- rhs[i+j-2] += int32_t(product - (overflow * OVER_SEG));
|
|
|
- rhs[i+j-1] += int32_t(overflow);
|
|
|
+ size_t const to = i+j-2-offset;
|
|
|
+ rhs[to] += int32_t(product - (overflow * OVER_SEG));
|
|
|
+ rhs[to+1] += int32_t(overflow);
|
|
|
}
|
|
|
rhs[i-1] -= value;
|
|
|
}
|