コード例 #1
0
ファイル: pidigits.py プロジェクト: warnerjon12/mpmath
def calculateit(base, n, tofile):
    intpart = numeral(3, base)
    skip = 1
    if base <= 3:
        skip = 2

    prec = int(n * math.log(base, 2)) + 10

    print("Step 1 of 2: calculating binary value...")
    t = clock()
    a = pi_fixed(prec, verbose=True, verbose_base=base)
    step1_time = clock() - t

    print("Step 2 of 2: converting to specified base...")
    t = clock()
    d = bin_to_radix(a, prec, base, n)
    d = numeral(d, base, n)
    step2_time = clock() - t

    print("\nWriting output...\n")

    if tofile:
        out_ = sys.stdout
        sys.stdout = tofile
    print("%i base-%i digits of pi:\n" % (n, base))
    print(intpart, ".\n")

    display_fraction(d, skip, colwidth=10, columns=5)
    if tofile:
        sys.stdout = out_
    print("\nFinished in %f seconds (%f calc, %f convert)" % \
        ((step1_time + step2_time), step1_time, step2_time))
コード例 #2
0
ファイル: pidigits.py プロジェクト: zsolt-beringer/sympy
def calculateit(func, base, n, tofile):
    """Writes first n base-digits of a mpmath function to file"""
    prec = 100
    intpart = libmp.numeral(3, base)
    if intpart == 0:
        skip = 0
    else:
        skip = len(intpart)
    print("Step 1 of 2: calculating binary value...")
    prec = int(n * math.log(base, 2)) + 10
    t = clock()
    a = func(prec)
    step1_time = clock() - t
    print("Step 2 of 2: converting to specified base...")
    t = clock()
    d = libmp.bin_to_radix(a.man, -a.exp, base, n)
    d = libmp.numeral(d, base, n)
    step2_time = clock() - t
    print("\nWriting output...\n")
    if tofile:
        out_ = sys.stdout
        sys.stdout = tofile
    print("%i base-%i digits of pi:\n" % (n, base))
    print(intpart, ".\n")
    display_fraction(d, skip=skip, colwidth=10, columns=5)
    if tofile:
        sys.stdout = out_
    print("\nFinished in %f seconds (%f calc, %f convert)" % \
        ((step1_time + step2_time), step1_time, step2_time))
コード例 #3
0
ファイル: pidigits.py プロジェクト: 2t7/mpmath
def calculateit(base, n, tofile):
    intpart = numeral(3, base)
    skip = 1
    if base <= 3:
        skip = 2

    prec = int(n*math.log(base,2))+10

    print "Step 1 of 2: calculating binary value..."
    t = clock()
    a = pi_fixed(prec, verbose=True, verbose_base=base)
    step1_time = clock() - t

    print "Step 2 of 2: converting to specified base..."
    t = clock()
    d = bin_to_radix(a, prec, base, n)
    d = numeral(d, base, n)
    step2_time = clock() - t

    print "\nWriting output...\n"

    if tofile:
        out_ = sys.stdout
        sys.stdout = tofile
    print "%i base-%i digits of pi:\n" % (n, base)
    print intpart, ".\n"

    display_fraction(d, skip, colwidth=10, columns=5)
    if tofile:
        sys.stdout = out_
    print "\nFinished in %f seconds (%f calc, %f convert)" % \
        ((step1_time + step2_time), step1_time, step2_time)
コード例 #4
0
ファイル: pidigits.py プロジェクト: A-turing-machine/sympy
def calculateit(func, base, n, tofile):
    """Writes first n base-digits of a mpmath function to file"""
    prec = 100
    intpart = libmp.numeral(3, base)
    if intpart == 0:
        skip = 0
    else:
        skip = len(intpart)
    print("Step 1 of 2: calculating binary value...")
    prec = int(n*math.log(base, 2)) + 10
    t = clock()
    a = func(prec)
    step1_time = clock() - t
    print("Step 2 of 2: converting to specified base...")
    t = clock()
    d = libmp.bin_to_radix(a.man, -a.exp, base, n)
    d = libmp.numeral(d, base, n)
    step2_time = clock() - t
    print("\nWriting output...\n")
    if tofile:
        out_ = sys.stdout
        sys.stdout = tofile
    print("%i base-%i digits of pi:\n" % (n, base))
    print(intpart, ".\n")
    display_fraction(d, skip, colwidth=10, columns=5)
    if tofile:
        sys.stdout = out_
    print("\nFinished in %f seconds (%f calc, %f convert)" % \
        ((step1_time + step2_time), step1_time, step2_time))
コード例 #5
0
ファイル: manydigits.py プロジェクト: zequequiel/mpmath
def pr(x):
    """Return the first dps digits after the decimal point"""
    x = x._mpf_
    p = int(dps * 3.33 + 10)
    t = to_fixed(x, p)
    d = bin_to_radix(t, p, 10, dps)
    s = str(d).zfill(dps)[-dps:]
    return s[:dps // 2] + "\n" + s[dps // 2:]
コード例 #6
0
ファイル: manydigits.py プロジェクト: 2t7/mpmath
def pr(x):
    """Return the first dps digits after the decimal point"""
    x = x._mpf_
    p = int(dps*3.33 + 10)
    t = to_fixed(x, p)
    d = bin_to_radix(t, p, 10, dps)
    s = str(d).zfill(dps)[-dps:]
    return s[:dps//2] + "\n" + s[dps//2:]