summaryrefslogtreecommitdiff
path: root/big.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 13:50:40 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 13:50:40 -0400
commitfc8fda1611d7dc2b274a25adbf3f81ffa2a37beb (patch)
tree8ac70c22bf7757b24876ac23c25e355e9591e99a /big.c
parentfe7cdece38c588a4481a24e67a89fda07cd2e53a (diff)
modernize bigsetup(), isnat(), and sto_int()
Diffstat (limited to 'big.c')
-rw-r--r--big.c33
1 files changed, 18 insertions, 15 deletions
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)