summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 14:21:22 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 14:21:22 -0400
commitcfe7ab38754d9b5855c1537c5b55fa7b44c1c578 (patch)
tree6faa1134bf350facc995a39fe7320eaa15b94310
parent2b0d84761577dea4fc5282593305440290ab1696 (diff)
modernize bigcmp()
-rw-r--r--big.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/big.c b/big.c
index 49d9598..0ebd8fa 100644
--- a/big.c
+++ b/big.c
@@ -265,26 +265,34 @@ word big_sub(word x, word y)
return r;
}
-int bigcmp(x, y) /* returns +ve,0,-ve as x greater than, equal, less than y */
-word x, y;
+/* returns +ve,0,-ve as x greater than, equal, less than y */
+int bigcmp(word x, word y)
{
- word d, r, s = big_is_negative(x);
- if (big_is_negative(y) != s)
+ word s = big_is_negative(x);
+ if (big_is_negative(y) != s) {
return (s ? -1 : 1);
- r = digit0(x) - digit0(y);
+ }
+
+ word r = digit0(x) - digit0(y);
for (;;) {
x = rest(x);
y = rest(y);
- if (!x)
- if (y)
+
+ if (!x) {
+ if (y) {
return (s ? 1 : -1);
- else
- return (s ? -r : r);
- if (!y)
+ }
+ return (s ? -r : r);
+ }
+
+ if (!y) {
return (s ? -1 : 1);
- d = digit(x) - digit(y);
- if (d)
+ }
+
+ word d = digit(x) - digit(y);
+ if (d) {
r = d;
+ }
}
}