Skip to content

Instantly share code, notes, and snippets.

@charlesBochet
Created February 7, 2019 15:37
Show Gist options
  • Save charlesBochet/190cbdc50a9b6e9af50f2f8350bbc071 to your computer and use it in GitHub Desktop.
Save charlesBochet/190cbdc50a9b6e9af50f2f8350bbc071 to your computer and use it in GitHub Desktop.
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