Skip to content

Instantly share code, notes, and snippets.

@alaztetik
Last active April 20, 2019 23:43
Show Gist options
  • Save alaztetik/9b42e5a3e360c8574c9ce4f0a2366ea0 to your computer and use it in GitHub Desktop.
Save alaztetik/9b42e5a3e360c8574c9ce4f0a2366ea0 to your computer and use it in GitHub Desktop.
Leibniz PI Formula
// REV 03-19042101
function pi(n) {
var v = 0;
for (i = 1; i <= n; i += 4) { // increment by 4
v += 1 / i - 1 / (i + 2); // add the value of the series
}
return 4 * v; // apply the factor at last
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment