diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-08 15:07:23 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-08 15:07:23 +0200 |
commit | 27472e604eeb74b3b60313d38d537c7e0e83151b (patch) | |
tree | a83de3767ccf64b7c512c5c9329bf38cd5b75940 /bigint.h | |
parent | 00c059d4554f70fc52d94ff1d5dd28976bf857fb (diff) |
Fix sign issues in divmod
Diffstat (limited to 'bigint.h')
-rw-r--r-- | bigint.h | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -26,7 +26,7 @@ private: void normalise(); void checkconsistent(); - std::pair<Bigint,Bigint> divmod(const Bigint&,int depth,int maxdepth) const; + std::pair<Bigint,Bigint> divmod(const Bigint&,int depth,int maxdepth) const; //ignores all signs public: Bigint(); @@ -63,7 +63,11 @@ public: Bigint operator*(slongdigit_t) const; Bigint operator<<(int) const; Bigint operator>>(int) const; - std::pair<Bigint,Bigint> divmod(const Bigint&) const; //rounds towards zero; returns {quotient,remainder} + + //Uses *mathematical* division-with-remainder. + //If we look at {q,r} = x.divmod(y), then x = q*y + r, and 0<=r<|q|. This is *not* compatible with many other + //programming languages (and, for that matter, the C++ built-in behaviour). + std::pair<Bigint,Bigint> divmod(const Bigint&) const; bool operator==(const Bigint&) const; bool operator!=(const Bigint&) const; |