def _del_mpz(mpz): global in_mpz_cache if in_mpz_cache < cache_size: if ffi.sizeof(mpz[0]) <= cache_obsize: mpz_cache[in_mpz_cache] = mpz else: mpz_cache[in_mpz_cache] = ffi.new('mpz_t') in_mpz_cache += 1 else: gmp.mpz_clear(mpz)
def _pyint_to_mpfr(n, a): if -sys.maxsize - 1 <= n <= sys.maxsize: gmp.mpfr_set_si(a, n, gmp.MPFR_RNDN) elif sys.maxsize < n <= MAX_UI: gmp.mpfr_set_ui(a, n, gmp.MPFR_RNDN) else: assert isinstance(n, long) tmp_mpz = ffi.new('mpz_t') gmp.mpz_init(tmp_mpz) _pylong_to_mpz(n, tmp_mpz) gmp.mpfr_set_z(a, tmp_mpz, gmp.MPFR_RNDN) gmp.mpz_clear(tmp_mpz)