diff options
Diffstat (limited to 'py/smallint.h')
| -rw-r--r-- | py/smallint.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/py/smallint.h b/py/smallint.h index 67daf9b9f..584e0018d 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -61,6 +61,13 @@ #define MP_SMALL_INT_MAX ((mp_int_t)(~(MP_SMALL_INT_MIN))) +// https://stackoverflow.com/a/4589384/1976323 +// Number of bits in inttype_MAX, or in any (1<<k)-1 where 0 <= k < 2040 +#define MP_IMAX_BITS(m) ((m) / ((m) % 255 + 1) / 255 % 255 * 8 + 7 - 86 / ((m) % 255 + 12)) + +// The number of bits in a MP_SMALL_INT including the sign bit. +#define MP_SMALL_INT_BITS (MP_IMAX_BITS(MP_SMALL_INT_MAX) + 1) + bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y); mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor); mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom); |
