Created
February 21, 2018 15:17
-
-
Save jiggzson/c065fabe56c2ae1a4ece36463e33a487 to your computer and use it in GitHub Desktop.
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
var factorial = function(n) { | |
++n; | |
var r = 1; | |
while(n-->1) | |
r*=n; | |
return r; | |
} | |
var calculatePI = function(n) { | |
n = n || 30; | |
var k = Math.sqrt(2)*2/9801; | |
var sum = 0; | |
for(var i=0; i<n; i++) { | |
sum += (factorial(4*i)*(1103+26390*i))/ | |
(Math.pow(factorial(i), 4)*Math.pow(396, 4*i)); | |
} | |
return 1/(sum*k) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment