summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--big.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/big.c b/big.c
index 72842fc..022b49d 100644
--- a/big.c
+++ b/big.c
@@ -14,7 +14,11 @@
#include "big.h"
#include <errno.h>
-static double logIBASE, log10IBASE;
+#define MAX_INT_BITS 60
+#define LONG_LONG_OVERFLOW (1ll<<MAX_INT_BITS)
+
+static double logIBASE;
+static double log10IBASE;
word big_one;
static word big_plus(word, word, int);
@@ -59,26 +63,30 @@ word sto_int(long long i)
}
return x;
-} /* change to long long, DT Oct 2019 */
-
-#define maxval (1ll<<60)
+}
-long long get_int(x) /* mira bigint to C long long */
-word x;
+/* mira bigint to C long long */
+long long get_int(word x)
{
long long n = digit0(x);
word sign = big_is_negative(x);
- if (!(x = rest(x)))
- return (sign ? -n : n);
- {
- word w = DIGITWIDTH;
- while (x && w < 60)
- n += (long long)digit(x) << w, w += DIGITWIDTH, x = rest(x);
- if (x)
- n = maxval; /* overflow, return large value */
+ if (!(x = rest(x))) {
return (sign ? -n : n);
}
-} /* change to long long, DT Oct 2019 */
+
+ word w = DIGITWIDTH;
+ while (x && w < MAX_INT_BITS) {
+ n += (long long)digit(x) << w;
+ w += DIGITWIDTH;
+ x = rest(x);
+ }
+
+ if (x) {
+ n = LONG_LONG_OVERFLOW;
+ }
+
+ return (sign ? -n : n);
+}
word bignegate(x)
word x;