From 27472e604eeb74b3b60313d38d537c7e0e83151b Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 8 Oct 2016 15:07:23 +0200 Subject: Fix sign issues in divmod --- bigint.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bigint.h') 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 divmod(const Bigint&,int depth,int maxdepth) const; + std::pair 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 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 divmod(const Bigint&) const; bool operator==(const Bigint&) const; bool operator!=(const Bigint&) const; -- cgit v1.2.3-70-g09d2