aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-05-11 18:22:11 +0200
committerMattias Andrée <maandree@kth.se>2016-05-11 18:25:15 +0200
commit0703ea9ea4155d59d1356713789c60f5e6e8c7a6 (patch)
tree77b55910f77563e4fc2c8ba77351ebaba876d602 /src
parentFix typo (diff)
downloadlibzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.gz
libzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.bz2
libzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.xz
Always satisfy n=qd+r to avoid confusion
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/zdivmod.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/zdivmod.c b/src/zdivmod.c
index dae0e02..80b75df 100644
--- a/src/zdivmod.c
+++ b/src/zdivmod.c
@@ -67,9 +67,10 @@ done:
void
zdivmod(z_t a, z_t b, z_t c, z_t d)
{
- int sign, cmpmag;
+ int c_sign, sign, cmpmag;
- sign = zsignum(c) * zsignum(d);
+ c_sign = zsignum(c);
+ sign = c_sign * zsignum(d);
if (unlikely(!sign)) {
if (check(!zzero(c))) {
@@ -87,7 +88,6 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
SET_SIGNUM(b, 0);
} else {
SET(b, c);
- SET_SIGNUM(b, 1);
SET_SIGNUM(a, 0);
}
return;
@@ -95,4 +95,6 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
zdivmod_impl(a, b, c, d);
SET_SIGNUM(a, sign);
+ if (zsignum(b) > 0)
+ SET_SIGNUM(b, c_sign);
}