summaryrefslogtreecommitdiff
path: root/big.c
diff options
context:
space:
mode:
Diffstat (limited to 'big.c')
-rw-r--r--big.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/big.c b/big.c
index 919390d..f791b4d 100644
--- a/big.c
+++ b/big.c
@@ -117,17 +117,17 @@ word bigplus(word x, word y)
}
/* ignore input signs, treat x,y as positive */
-word big_plus(x, y, signbit)
-word x, y;
-int signbit;
+word big_plus(word x, word y, int signbit)
{
word d = digit0(x) + digit0(y);
- word carry = ((d & IBASE) != 0);
word r = make(INT, signbit | d & MAXDIGIT, 0); /* result */
word *z = &rest(r); /* pointer to rest of result */
+
+ word carry = ((d & IBASE) != 0);
x = rest(x);
y = rest(y);
- while (x && y) { /* this loop has been unwrapped once, see above */
+
+ while (x && y) {
d = carry + digit(x) + digit(y);
carry = ((d & IBASE) != 0);
*z = make(INT, d & MAXDIGIT, 0);
@@ -135,8 +135,11 @@ int signbit;
y = rest(y);
z = &rest(*z);
}
- if (y)
+
+ if (y) {
x = y; /* by convention x is the longer one */
+ }
+
while (x) {
d = carry + digit(x);
carry = ((d & IBASE) != 0);
@@ -144,9 +147,12 @@ int signbit;
x = rest(x);
z = &rest(*z);
}
- if (carry)
+
+ if (carry) {
*z = make(INT, 1, 0);
- return (r);
+ }
+
+ return r;
}
word bigsub(x, y)