Merge pull request #4845 from t-ikegami/mpz_crash_fix
Fix bit_length() method to work with zero-valued mpz integer.
This commit is contained in:
commit
a25872dcb3
3
py/mpz.h
3
py/mpz.h
|
@ -142,6 +142,9 @@ static inline size_t mpz_max_num_bits(const mpz_t *z) {
|
|||
return z->len * MPZ_DIG_SIZE;
|
||||
}
|
||||
static inline size_t mpz_num_bits(const mpz_t *z) {
|
||||
if (mpz_is_zero(z)) {
|
||||
return 0;
|
||||
}
|
||||
size_t last_bits = (8 * (sizeof(long) - sizeof(mpz_dig_t))) - __builtin_clzl(z->dig[z->len - 1]);
|
||||
return z->len * MPZ_DIG_SIZE + last_bits;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue