summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--big.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/big.c b/big.c
index d5341ac..fc9a452 100644
--- a/big.c
+++ b/big.c
@@ -398,25 +398,33 @@ word bigdiv(word x, word y)
return q;
}
-word bigmod(x, y) /* may assume y~=0 */
-word x, y;
+/* may assume y~=0 */
+word bigmod(word x, word y)
{
- word s1, s2;
+ word s1 = big_is_negative(y);
+ word s2 = s1;
+
/* make x,y positive and remember signs */
- if (s1 = big_is_negative(y))
+ if (s1) {
y = make(INT, digit0(y), rest(y));
- if (big_is_negative(x))
- x = make(INT, digit0(x), rest(x)), s2 = !s1;
- else
- s2 = s1;
+ }
+
+ if (big_is_negative(x)) {
+ x = make(INT, digit0(x), rest(x));
+ s2 = !s1;
+ }
+
/* effect: s1 set iff y negative, s2 set iff signs mixed */
- if (rest(y))
+ if (rest(y)) {
longdiv(x, y);
- else
+ } else {
shortdiv(x, digit(y));
+ }
+
if (s2) {
- if (!bigzero(b_rem))
+ if (!bigzero(b_rem)) {
b_rem = bigsub(y, b_rem);
+ }
}
return (s1 ? bignegate(b_rem) : b_rem);
}