aboutsummaryrefslogtreecommitdiffstats
path: root/src/zdivmod.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-04 23:50:00 +0100
committerMattias Andrée <maandree@kth.se>2016-03-04 23:50:00 +0100
commit76d0af5599554d11f104d582cdac8fbaa8569fcc (patch)
tree0ed9889a86d52ebd208382f2fd49dad0570d1f8c /src/zdivmod.c
parentClean up, fix a few bugs, and add a test (diff)
downloadlibzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.gz
libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.bz2
libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.xz
Clean up, add zerror and zperror, fix bugs and add more tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zdivmod.c')
-rw-r--r--src/zdivmod.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/zdivmod.c b/src/zdivmod.c
index 9340810..e145c27 100644
--- a/src/zdivmod.c
+++ b/src/zdivmod.c
@@ -18,15 +18,13 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
if (!sign) {
if (zzero(c)) {
if (zzero(d)) {
- errno = EDOM; /* Indeterminate form: 0 divided by 0 */
- FAILURE_JUMP();
+ FAILURE(EDOM); /* Indeterminate form: 0 divided by 0 */
} else {
SET_SIGNUM(a, 0);
SET_SIGNUM(b, 0);
}
} else {
- errno = EDOM; /* Undefined form: Division by 0 */
- FAILURE_JUMP();
+ FAILURE(EDOM); /* Undefined form: Division by 0 */
}
return;
} else if ((cmpmag = zcmpmag(c, d)) <= 0) {
@@ -64,7 +62,7 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
zsub(tb, tb, td);
zbset(ta, ta, bit, 1);
}
- if (!bit--)
+ if (!bit-- || zzero(tb))
goto done;
zrsh(td, td, 1);
}
@@ -78,11 +76,10 @@ zdivmod(z_t a, z_t b, z_t c, z_t d)
zsub(tb, tb, tds[i]);
zbset(ta, ta, bit, 1);
}
- if (!bit--)
+ if (!bit-- || zzero(tb))
goto done;
- zrsh(tds[i], tds[i], 1);
}
- for (i = MIN(bit, BITS_PER_CHAR); i--;)
+ for (i = MIN(bit, BITS_PER_CHAR - 1) + 1; i--;)
zrsh(tds[i], tds[i], BITS_PER_CHAR);
}
}