Created
February 7, 2019 15:36
-
-
Save charlesBochet/2e7e915e8ee6b97f8a82fab75543caab 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)) | |
} | |
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