def __int__(self): # buf will contain the integer encoded in decimal plus the trailing # zero, and possibly the negative sign. # dig10(x) < log10(x) + 1 = log2(x)/log2(10) + 1 < log2(x)/3 + 1 buf_len = _gmp.mpz_sizeinbase(self._mpz_p, 2) // 3 + 3 buf = create_string_buffer(buf_len) _gmp.gmp_snprintf(buf, c_size_t(buf_len), b"%Zd", self._mpz_p) return int(get_c_string(buf))
def __int__(self): # buf will contain the integer encoded in decimal plus the trailing # zero, and possibly the negative sign. # dig10(x) < log10(x) + 1 = log2(x)/log2(10) + 1 < log2(x)/3 + 1 buf_len = _gmp.mpz_sizeinbase(self._mpz_p, 2) // 3 + 3 buf = create_string_buffer(buf_len) _gmp.gmp_snprintf(buf, c_size_t(buf_len), b("%Zd"), self._mpz_p) return int(get_c_string(buf))