From db28fcf89f08307ca5f13cbb9d562ac0e5f9431e Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 14:11:39 -0400 Subject: modernize bigsub() --- big.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'big.c') diff --git a/big.c b/big.c index f791b4d..c35ce99 100644 --- a/big.c +++ b/big.c @@ -155,18 +155,20 @@ word big_plus(word x, word y, int signbit) return r; } -word bigsub(x, y) -word x, y; +word bigsub(word x, word y) { - if (big_is_positive(x)) - if (big_is_positive(y)) - return (big_sub(x, y)); - else - return (big_plus(x, y, 0)); /* big_is_positive x, negative y */ - else if (big_is_positive(y)) - return (big_plus(x, y, SIGNBIT)); /* negative x, big_is_positive y */ - else - return (big_sub(y, x)); /* both negative */ + if (big_is_positive(x)) { + if (big_is_positive(y)) { + return (big_sub(x, y)); /* both positive */ + } + return (big_plus(x, y, 0)); /* positive x, negative y */ + } + + if (big_is_positive(y)) { + return (big_plus(x, y, SIGNBIT)); /* negative x, positive y */ + } + + return (big_sub(y, x)); /* both negative */ } word big_sub(x, y) /* ignore input signs, treat x,y as positive */ -- cgit v1.2.1