summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */