aboutsummaryrefslogtreecommitdiffstats
path: root/src/znot.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-05 20:16:14 +0100
committerMattias Andrée <maandree@kth.se>2016-03-05 20:16:14 +0100
commit5860237d2f05f6ae45a98569b0d567c2227904c6 (patch)
treebbddb91e2a6a5e7efe7825971c726a9e4db87dd6 /src/znot.c
parentMore detailed description of division and modulus (diff)
downloadlibzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.gz
libzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.bz2
libzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.xz
Fix bugs and add a randomised testing
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/znot.c')
-rw-r--r--src/znot.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/znot.c b/src/znot.c
index bcb17e2..d0e52c0 100644
--- a/src/znot.c
+++ b/src/znot.c
@@ -18,12 +18,12 @@ znot(z_t a, z_t b)
for (n = a->used; n--;)
a->chars[n] = ~(a->chars[n]);
- bits &= BITS_PER_CHAR - 1;
- a->chars[a->used - 1] &= ((zahl_char_t)1 << bits) - 1;
+ bits = BITS_IN_LAST_CHAR(bits);
+ if (bits)
+ a->chars[a->used - 1] &= ((zahl_char_t)1 << bits) - 1;
- for (; a->used; a->used--)
- if (a->chars[a->used - 1])
- break;
+ while (a->used && !a->chars[a->used - 1])
+ a->used--;
if (!a->used)
SET_SIGNUM(a, 0);
}