Created
February 7, 2019 15:37
-
-
Save charlesBochet/190cbdc50a9b6e9af50f2f8350bbc071 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
function computePi() { | |
document.getElementById('pi').innerHTML = (4 * atan(1/5) - atan(1/239)) * 4 | |
} | |
function atan(x) { | |
var result = x; | |
var xSquared = x * x; | |
var term = x; | |
var divisor = 1; | |
while (term != 0) { | |
divisor += 2; | |
term *= xSquared; | |
result -= term / divisor; | |
divisor += 2; | |
term *= xSquared; | |
result += term / divisor; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment