summaryrefslogtreecommitdiff
path: root/lisp/mp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mp')
-rw-r--r--lisp/mp/mp.c12
-rw-r--r--lisp/mp/mp.h2
-rw-r--r--lisp/mp/mpi.c8
3 files changed, 12 insertions, 10 deletions
diff --git a/lisp/mp/mp.c b/lisp/mp/mp.c
index 2afb343..cf24768 100644
--- a/lisp/mp/mp.c
+++ b/lisp/mp/mp.c
@@ -190,19 +190,19 @@ mp_add(BNS *rop, BNS *op1, BNS *op2, BNI len1, BNI len2)
MP_SWAP(op1, op2, len1, len2);
/* unroll start of loop */
- value = op1[0] + op2[0];
+ value = (BNI)op1[0] + op2[0];
rop[0] = value;
carry = value >> BNSBITS;
/* add op1 and op2 */
for (size = 1; size < len2; size++) {
- value = op1[size] + op2[size] + carry;
+ value = (BNI)op1[size] + op2[size] + carry;
rop[size] = value;
carry = value >> BNSBITS;
}
if (rop != op1) {
for (; size < len1; size++) {
- value = op1[size] + carry;
+ value = (BNI)op1[size] + carry;
rop[size] = value;
carry = value >> BNSBITS;
}
@@ -210,7 +210,7 @@ mp_add(BNS *rop, BNS *op1, BNS *op2, BNI len1, BNI len2)
else {
/* if rop == op1, than just adjust carry */
for (; carry && size < len1; size++) {
- value = op1[size] + carry;
+ value = (BNI)op1[size] + carry;
rop[size] = value;
carry = value >> BNSBITS;
}
@@ -237,7 +237,7 @@ mp_sub(BNS *rop, BNS *op1, BNS *op2, BNI len1, BNI len2)
}
/* unroll start of loop */
- svalue = op1[0] - op2[0];
+ svalue = (long)op1[0] - op2[0];
rop[0] = svalue;
carry = svalue < 0;
@@ -257,7 +257,7 @@ mp_sub(BNS *rop, BNS *op1, BNS *op2, BNI len1, BNI len2)
else {
/* if rop == op1, than just adjust carry */
for (; carry && size < len1; size++) {
- svalue = op1[size] - carry;
+ svalue = (long)op1[size] - carry;
rop[size] = svalue;
carry = svalue < 0;
}
diff --git a/lisp/mp/mp.h b/lisp/mp/mp.h
index 8bcb127..c5a74f3 100644
--- a/lisp/mp/mp.h
+++ b/lisp/mp/mp.h
@@ -76,6 +76,7 @@
# define BNI unsigned long
# define BNS unsigned int
# define MINSLONG 0x8000000000000000UL
+# define MAXSLONG 0x7fffffffffffffffUL
# define CARRY 0x100000000
# define LMASK 0xffffffff00000000UL
# define SMASK 0x00000000ffffffffUL
@@ -89,6 +90,7 @@
# define BNI unsigned long
# define BNS unsigned short
# define MINSLONG 0x80000000UL
+# define MAXSLONG 0x7fffffffUL
# define CARRY 0x10000
# define LMASK 0xffff0000UL
# define SMASK 0x0000ffffUL
diff --git a/lisp/mp/mpi.c b/lisp/mp/mpi.c
index fabe366..447bd23 100644
--- a/lisp/mp/mpi.c
+++ b/lisp/mp/mpi.c
@@ -318,7 +318,7 @@ mpi_setstr(mpi *rop, char *str, int base)
if (islower(value))
value = toupper(value);
value = value > '9' ? value - 'A' + 10 : value - '0';
- value += rop->digs[0] * base;
+ value += (BNI)rop->digs[0] * base;
carry = value >> BNSBITS;
rop->digs[0] = (BNS)value;
for (i = 1; i < size; i++) {
@@ -642,10 +642,10 @@ mpi_divqr(mpi *qrop, mpi *rrop, mpi *num, mpi *den)
if (ndigs[npos] == ddigs[dpos])
qest = (BNS)SMASK;
else
- qest = (BNS)((((BNI)(ndigs[npos]) << 16) + ndigs[npos - 1]) /
+ qest = (BNS)((((BNI)(ndigs[npos]) << BNSBITS) + ndigs[npos - 1]) /
ddigs[dpos]);
- while ((value = ((BNI)(ndigs[npos]) << 16) + ndigs[npos - 1] -
+ while ((value = ((BNI)(ndigs[npos]) << BNSBITS) + ndigs[npos - 1] -
qest * (BNI)(ddigs[dpos])) < CARRY &&
ddigs[dpos - 1] * (BNI)qest >
(value << BNSBITS) + ndigs[npos - 2])
@@ -1603,7 +1603,7 @@ mpi_getstr(char *str, mpi *op, int base)
/* make copy of op data and adjust digs */
xdigs = mp_malloc(size * sizeof(BNS));
- memcpy(xdigs, op->digs, size * sizeof(unsigned short));
+ memcpy(xdigs, op->digs, size * sizeof(BNS));
digs = xdigs + size - 1;
/* convert to string */