Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > value of pi and 22/7

Thread Tools

value of pi and 22/7

Gerald Britton
Posts: n/a
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.

Gerald Britton
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What happens if adding a very big value and a very small value? ericnoonan C++ 0 12-14-2009 06:57 AM
How Do I Locate a value in a text file and evaluate it and then writeout that line based on the value? kwalike57 Perl Misc 7 01-03-2008 06:20 PM
Function take in value and return value CSINVA ASP .Net 6 11-07-2007 12:49 PM
[ConfigParser] value with ; and the value blank kai Python 1 05-05-2006 05:18 PM
The value of Big-O notation is for scale ability and the value of the constant of proportionality! Casey Hawthorne Python 0 10-17-2005 03:00 AM