diff options
Diffstat (limited to 'boost/multiprecision/cpp_int/divide.hpp')
-rw-r--r-- | boost/multiprecision/cpp_int/divide.hpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/boost/multiprecision/cpp_int/divide.hpp b/boost/multiprecision/cpp_int/divide.hpp index c94bc71498..5fe6ce6ad8 100644 --- a/boost/multiprecision/cpp_int/divide.hpp +++ b/boost/multiprecision/cpp_int/divide.hpp @@ -242,7 +242,21 @@ void divide_unsigned_helper( // Update r in a way that won't actually produce a negative result // in case the argument types are unsigned: // - if(r.compare(t) > 0) + if(truncated_t && carry) + { + // We need to calculate 2^n + t - r + // where n is the number of bits in this type. + // Simplest way is to get 2^n - r by complementing + // r, then add t to it. Note that we can't call eval_complement + // in case this is a signed checked type: + for(unsigned i = 0; i <= r_order; ++i) + r.limbs()[i] = ~prem[i]; + r.normalize(); + eval_increment(r); + eval_add(r, t); + r_neg = !r_neg; + } + else if(r.compare(t) > 0) { eval_subtract(r, t); } |