aboutsummaryrefslogtreecommitdiffstats
path: root/src/zpow.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-04 10:45:10 +0100
committerMattias Andrée <maandree@kth.se>2016-03-04 10:47:53 +0100
commitaff09967d194d062ae8d83c0fbe1edf158804ef9 (patch)
tree793f32bc01e780bb6457570f9ea7a8e7ff94f7bb /src/zpow.c
parentAdd makefile and fix errors (diff)
downloadlibzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.gz
libzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.bz2
libzahl-aff09967d194d062ae8d83c0fbe1edf158804ef9.tar.xz
Clean up, fix a few bugs, and add a test
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zpow.c')
-rw-r--r--src/zpow.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/zpow.c b/src/zpow.c
index 16988f7..c064f60 100644
--- a/src/zpow.c
+++ b/src/zpow.c
@@ -37,7 +37,7 @@ zpow(z_t a, z_t b, z_t c)
zset(tc, c);
zsetu(a, 1);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; i++) { /* Remember, n is floored. */
x = tc->chars[i];
for (j = BITS_PER_CHAR; j--; x >>= 1) {
if (x & 1)
@@ -45,4 +45,10 @@ zpow(z_t a, z_t b, z_t c)
zsqr(tb, tb);
}
}
+ x = tc->chars[i];
+ for (; x; x >>= 1) {
+ if (x & 1)
+ zmul(a, a, tb);
+ zsqr(tb, tb);
+ }
}