aboutsummaryrefslogtreecommitdiff
path: root/py/mpz.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-09-15 16:15:57 +0100
committerDamien George <damien.p.george@gmail.com>2015-09-15 16:15:57 +0100
commit8b4fb4fe140e9cf57fcfa258d0d2d6fe19090fc5 (patch)
treef37cb4277e50faa6d3116a7c9ebcb15395646caa /py/mpz.h
parentb230a86d332376d15b61636111ce47c90a5ab54a (diff)
py/mpz: Fix calculation of max digit storage for mpz; fix sys.maxsize.
When creating constant mpz's, the length of the mpz must be exactly how many digits are used (not allocated) otherwise these numbers are not compatible with dynamically allocated numbers. Addresses issue #1448.
Diffstat (limited to 'py/mpz.h')
-rw-r--r--py/mpz.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/py/mpz.h b/py/mpz.h
index b00d2b655..e287cdd10 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -78,8 +78,9 @@ typedef int8_t mpz_dbl_dig_signed_t;
#define MPZ_LONG_1 1L
#endif
-#define MPZ_NUM_DIG_FOR_INT (sizeof(mp_int_t) * 8 / MPZ_DIG_SIZE + 1)
-#define MPZ_NUM_DIG_FOR_LL (sizeof(long long) * 8 / MPZ_DIG_SIZE + 1)
+// these define the maximum storage needed to hold an int or long long
+#define MPZ_NUM_DIG_FOR_INT ((sizeof(mp_int_t) * 8 + MPZ_DIG_SIZE - 1) / MPZ_DIG_SIZE)
+#define MPZ_NUM_DIG_FOR_LL ((sizeof(long long) * 8 + MPZ_DIG_SIZE - 1) / MPZ_DIG_SIZE)
typedef struct _mpz_t {
mp_uint_t neg : 1;