From cfe7ab38754d9b5855c1537c5b55fa7b44c1c578 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 14:21:22 -0400 Subject: modernize bigcmp() --- big.c | 32 ++++++++++++++++++++------------ 1 file 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; + } } } -- cgit v1.2.1