From fc8fda1611d7dc2b274a25adbf3f81ffa2a37beb Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 13:50:40 -0400 Subject: modernize bigsetup(), isnat(), and sto_int() --- big.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'big.c') diff --git a/big.c b/big.c index 1b276e2..72842fc 100644 --- a/big.c +++ b/big.c @@ -27,35 +27,38 @@ static word shift(word, word); static word shortdiv(word, word); static word stimes(word, word); -void bigsetup() +void bigsetup(void) { logIBASE = log((double)IBASE); log10IBASE = log10((double)IBASE); big_one = make(INT, 1, 0); } -int isnat(x) -word x; +int isnat(word x) { return (tag[x] == INT && big_is_positive(x)); } -word sto_int(i) /* store C long long as mira bigint */ -long long i; +/* store C long long as mira bigint */ +word sto_int(long long i) { - word s, x; - if (i < 0) - s = SIGNBIT, i = -i; - else - s = 0; - x = make(INT, s | i & MAXDIGIT, 0); + word sign = 0; + + if (i < 0) { + sign = SIGNBIT; + i = -i; + } + + word x = make(INT, (sign | i) & MAXDIGIT, 0); if (i >>= DIGITWIDTH) { word *p = &rest(x); - *p = make(INT, i & MAXDIGIT, 0), p = &rest(*p); - while (i >>= DIGITWIDTH) - *p = make(INT, i & MAXDIGIT, 0), p = &rest(*p); + do { + *p = make(INT, i & MAXDIGIT, 0); + p = &rest(*p); + } while (i >>= DIGITWIDTH); } - return (x); + + return x; } /* change to long long, DT Oct 2019 */ #define maxval (1ll<<60) -- cgit v1.2.1