summaryrefslogtreecommitdiff
path: root/big.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 14:36:21 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 14:36:21 -0400
commitd0d201d860eeb30ddf9fc5bc9dc9e22f678af43f (patch)
tree9dee174d23c0157420e65d4ca2e65b1597e99c52 /big.c
parent00fa74c7c906a1a21b703834c4c73b28777fe2e3 (diff)
modernize stimes()
Diffstat (limited to 'big.c')
-rw-r--r--big.c21
1 files changed, 14 insertions, 7 deletions
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 */