Beispiel #1
0
def _del_mpc(mpc):
    global in_mpc_cache

    if in_mpc_cache < cache_size:
        mpc_cache[in_mpc_cache] = mpc
        # FIXME This doesn't seem to be working properly
        if ffi.sizeof(mpc[0]) <= cache_obsize:
            mpc_cache[in_mpc_cache] = mpc
        else:
            mpc_cache[in_mpc_cache] = ffi.new('mpc_t')
Beispiel #2
0
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)
Beispiel #3
0
def _mpz_to_pylong(a):
    """
    Convert a to a python long.

    :type a: mpz_t
    :rtype: long
    """

    size = ffi.sizeof('uint64_t')
    numb = 8 * size
    count = (gmp.mpz_sizeinbase(a, 2) + numb - 1) // numb
    p = ffi.new('uint64_t[]', count)
    gmp.mpz_export(p, ffi.NULL, 1, size, 0, 0, a)
    res = 0
    for n in p:
        res = (res << numb) + n

    return res * gmp.mpz_sgn(a)
Beispiel #4
0
def _mpz_to_pylong(a):
    """
    Convert a to a python long.

    :type a: mpz_t
    :rtype: long
    """

    size = ffi.sizeof('uint64_t')
    numb = 8 * size
    count = (gmp.mpz_sizeinbase(a, 2) + numb - 1) // numb
    p = ffi.new('uint64_t[]', count)
    gmp.mpz_export(p, ffi.NULL, 1, size, 0, 0, a)
    res = 0
    for n in p:
        res = (res << numb) + n

    return res * gmp.mpz_sgn(a)