Million decimal places in Python -


we delve infinite series in calculus , being said, i'm having fun it. derived own inverse tan infinte series in python , set 1 pi/4*4 pi. know it's not fastest algorithm, please let's not discuss algorithm. discuss how represent very small numbers in python. notice programs iterate series, stops somewhere @ 20 decimal places (give or take). tried using decimal module , pushed 509. want infinite (almost) representation.

is there way such thing? reckon no data type able handle such immensity, if can show me way around that, appreciate much.

python's decimal module requires specify "context," affects how precise representation be.

i might recommend gmpy2 type of thing - can calculation on rational numbers (arbitrary precision) , convert decimal @ last step.

here's example - substitute own algorithm needed:

import gmpy2 # see https://gmpy2.readthedocs.org/en/latest/mpfr.html gmpy2.get_context().precision = 10000 pi = 0 n in range(1000000):     # formula http://en.wikipedia.org/wiki/calculating_pi#arctangent     numer = pow(2, n + 1)     denom = gmpy2.bincoef(n + n, n) * (n + n + 1)     frac = gmpy2.mpq(numer, denom)     pi += frac     # print every 1000 iterations     if n % 1000 == 0:         print(gmpy2.mpfr(pi)) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -