diff options
Diffstat (limited to 'big.c')
-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 */ |