Skip to content

Instantly share code, notes, and snippets.

@charlesBochet
Created February 7, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesBochet/2e7e915e8ee6b97f8a82fab75543caab to your computer and use it in GitHub Desktop.
Save charlesBochet/2e7e915e8ee6b97f8a82fab75543caab to your computer and use it in GitHub Desktop.
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