def _pyint_to_mpq(n, a): if -sys.maxsize - 1 <= n <= sys.maxsize: gmp.mpq_set_si(a, n, 1) elif sys.maxsize < n <= MAX_UI: gmp.mpq_set_ui(a, n, 1) else: assert isinstance(n, long) num, den = gmp.mpq_numref(a), gmp.mpq_denref(a) _pylong_to_mpz(n, num) gmp.mpz_set_ui(den, 1)
def _pyint_to_mpz(n, a): """ Set `a` from `n`. :type n: int,long :type a: mpz_t """ if -sys.maxsize - 1 <= n <= sys.maxsize: gmp.mpz_set_si(a, n) elif sys.maxsize < n <= MAX_UI: gmp.mpz_set_ui(a, n) else: gmp.mpz_set_str(a, hex(n).rstrip('L').encode('UTF-8'), 0)