summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arith.c12
-rw-r--r--mpi/mpi.c22
2 files changed, 30 insertions, 4 deletions
diff --git a/arith.c b/arith.c
index d3f2b186..c195b7b0 100644
--- a/arith.c
+++ b/arith.c
@@ -247,18 +247,24 @@ dbl_ucnum c_dbl_unum(val n)
{
switch (type(n)) {
case CHR: case NUM:
- return coerce(cnum, n) >> TAG_SHIFT;
+ {
+ dbl_cnum cn = coerce(cnum, n) >> TAG_SHIFT;
+ if (cn >= 0)
+ return cn;
+ break;
+ }
case BGNUM:
if (mp_in_double_uintptr_range(mp(n))) {
double_uintptr_t out;
mp_get_double_uintptr(mp(n), &out);
return out;
}
- uw_throwf(error_s, lit("~s is out of unsigned ~a bit range"),
- n, num_fast(SIZEOF_DOUBLE_INTPTR * CHAR_BIT), nao);
+ break;
default:
type_mismatch(lit("~s is not an integer"), n, nao);
}
+ uw_throwf(error_s, lit("~s is out of unsigned ~a bit range"),
+ n, num_fast(SIZEOF_DOUBLE_INTPTR * CHAR_BIT), nao);
}
#endif
diff --git a/mpi/mpi.c b/mpi/mpi.c
index b1eb7e49..291f3d10 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -582,10 +582,30 @@ static int s_mp_in_big_range(mp_int *mp, double_uintptr_t lim, int unsig)
if (nd > ptrnd)
return 0;
+ if (neg) {
+ mp_digit *dp = DIGITS(mp);
+ const mp_digit Ox8__0 = MP_DIGIT_MAX ^ (MP_DIGIT_MAX >> 1);
+
+ switch (ptrnd) {
+ case 1:
+ if (dp[0] == Ox8__0)
+ return 1;
+ break;
+ case 2:
+ if (dp[0] == 0 && dp[1] == Ox8__0)
+ return 1;
+ break;
+ case 4:
+ if (dp[0] == 0 && dp[1] == 0 && dp[2] == 0 && dp[3] == Ox8__0)
+ return 1;
+ break;
+ }
+ }
+
{
mp_digit top = DIGITS(mp)[ptrnd - 1];
lim >>= ((ptrnd - 1) * MP_DIGIT_BIT);
- return (top - neg) <= lim;
+ return top <= lim;
}
}