From d0d201d860eeb30ddf9fc5bc9dc9e22f678af43f Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 14:36:21 -0400 Subject: modernize stimes() --- big.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'big.c') diff --git a/big.c b/big.c index 2a640e5..b7c1186 100644 --- a/big.c +++ b/big.c @@ -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 */ -- cgit v1.2.1