diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 14:36:21 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 14:36:21 -0400 |
commit | d0d201d860eeb30ddf9fc5bc9dc9e22f678af43f (patch) | |
tree | 9dee174d23c0157420e65d4ca2e65b1597e99c52 | |
parent | 00fa74c7c906a1a21b703834c4c73b28777fe2e3 (diff) |
modernize stimes()
-rw-r--r-- | big.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -334,19 +334,26 @@ word shift(word n, word x) return x; } -word stimes(x, n) /* multiply big x (>=0) by digit n (>0) */ -word x, n; +/* multiply big x (>=0) by digit n (>0) */ +word stimes(word x, word n) { unsigned d = n * digit0(x); /* ignore sign of x */ word carry = d >> DIGITWIDTH; word r = make(INT, d & MAXDIGIT, 0); word *y = &rest(r); - while (x = rest(x)) - d = n * digit(x) + carry, - *y = make(INT, d & MAXDIGIT, 0), y = &rest(*y), carry = d >> DIGITWIDTH; - if (carry) + + while (x = rest(x)) { + d = n * digit(x) + carry; + *y = make(INT, d & MAXDIGIT, 0); + y = &rest(*y); + carry = d >> DIGITWIDTH; + } + + if (carry) { *y = make(INT, carry, 0); - return (r); + } + + return r; } word b_rem; /* contains remainder from last call to longdiv or shortdiv */ |