(func, base, n, tofile)
Writes first n base-digits of a mpmath function to file
Writes first n base-digits of a mpmath function to file
Writes first n base - digits of a mpmath function to file
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))
def calculateit ( func , base , n , tofile ) : 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 ) )