value of pi and 22/7

G

Gerald Britton

Surely on track for the *slowest* way to compute pi in Python (or any
language for that matter):

math.sqrt( sum( pow(k,-2) for k in xrange(sys.maxint,0,-1) ) * 6. )

Based on the Riemann zeta function:

The sum of

1/k^2 for k = 1:infinity

converges to pi^2 / 6

Depending on your horsepower and the size of sys.maxint on your
machine, this may take a few *days* to run.

Note: The sum in the Python expression above runs in reverse to
minimize rounding errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top