コード例 #1
0
ファイル: increment_2.py プロジェクト: justadev8/553
def getGCD(a, b):
    num1 = mpz(rint_round(a))
    num2 = mpz(rint_round(b))

    # if num2%num1 ==0:
    #     return num1

    gcd_a_b = gcd(num1, num2)
    return gcd_a_b
コード例 #2
0
    def check(self, i):
        #区间大小
        diff = self.right - self.left

        #新的左右区间
        curleft = self.left + diff * self.lp1[i]
        curright = self.left + diff * self.rp1[i]

        #读取的数转化为小数
        decimal = gmpy2.mpfr(self.cur / self.log10)
        decimal = decimal - gmpy2.floor(decimal)

        #判断是否满足要求
        if curleft > decimal:
            return False
        if curright < decimal:
            return False

        #更新区间
        self.left = curleft
        self.right = curright

        #通过decimal计算新的cur,抛弃掉cur前导多余数字,cur维持为整数防止精度缺失
        self.cur = decimal*self.log10
        self.cur = gmpy2.rint_round(self.cur)
        return True
コード例 #3
0
def mpfr_roundToIntegral(rm, a):
    assert isinstance(a, MPF)
    if rm == RM_RNA:
        with gmpy2.local_context(mpfr_context(a)):
            mpfr_a = mpf_to_mpfr(a)
            mpfr_r = gmpy2.rint_round(mpfr_a)
            return mpfr_to_mpf(mpfr_r)
    else:
        check_rm(rm)
        with gmpy2.local_context(mpfr_context(a, rm)):
            mpfr_a = mpf_to_mpfr(a)
            mpfr_r = gmpy2.rint(mpfr_a)
            return mpfr_to_mpf(mpfr_r)
コード例 #4
0
 def __init__(self, n):
     self.n = n
     self.n_sq = n * n
     self.g = n + 1
     self.bits = mpz(rint_round(log2(self.n)))
コード例 #5
0
 def __init__(self, n):
     self.n = n
     self.n_sq = n * n
     self.g = n + 1
     self.bits=mpz(rint_round(log2(self.n)))