diff options
Diffstat (limited to 'big.c')
-rw-r--r-- | big.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -585,30 +585,39 @@ word ms2d(word x) return (digit(x) * IBASE + d); } -word bigpow(x, y) /* assumes y big_is_positive */ -word x, y; +/* assumes y big_is_positive */ +word bigpow(word x, word y) { - word d, r = make(INT, 1, 0); - while (rest(y)) { /* this loop has been unwrapped once, see below */ + word d; + word r = make(INT, 1, 0); + + /* this loop has been unwrapped once, see below */ + while (rest(y)) { word i = DIGITWIDTH; d = digit(y); while (i--) { - if (d & 1) + if (d & 1) { r = bigtimes(r, x); + } x = bigtimes(x, x); d >>= 1; } y = rest(y); } + d = digit(y); - if (d & 1) + if (d & 1) { r = bigtimes(r, x); + } + while (d >>= 1) { x = bigtimes(x, x); - if (d & 1) + if (d & 1) { r = bigtimes(r, x); + } } - return (r); + + return r; } double bigtodbl(x) |