Created
September 9, 2014 17:52
-
-
Save jesuscast/077c7e81c8ae07531fb0 to your computer and use it in GitHub Desktop.
Calculates pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import * | |
getcontext().prec = 100 | |
def calcPi(precision): | |
sign = 1.0 | |
denominator = 1 | |
sum = Decimal(0.0) | |
for i in range(precision): | |
sum += Decimal(1.0)/Decimal(denominator)*Decimal(sign) | |
sign = -sign | |
denominator = denominator+2 | |
return sum | |
print str(calcPi(100)*Decimal(4.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment