aboutsummaryrefslogtreecommitdiff
path: root/bigint.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-08 15:07:23 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-08 15:07:23 +0200
commit27472e604eeb74b3b60313d38d537c7e0e83151b (patch)
treea83de3767ccf64b7c512c5c9329bf38cd5b75940 /bigint.h
parent00c059d4554f70fc52d94ff1d5dd28976bf857fb (diff)
Fix sign issues in divmod
Diffstat (limited to 'bigint.h')
-rw-r--r--bigint.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/bigint.h b/bigint.h
index 02f3da3..1e8515a 100644
--- a/bigint.h
+++ b/bigint.h
@@ -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;