Skip to content

Instantly share code, notes, and snippets.

@alkhe
Last active December 9, 2015 16:25
Show Gist options
  • Save alkhe/0f5cf9fde718e4010115 to your computer and use it in GitHub Desktop.
Save alkhe/0f5cf9fde718e4010115 to your computer and use it in GitHub Desktop.
calculate pi with arctan series
let summation = (start, end, a) => {
let sum = 0;
for (let n = start; n <= end; n++) sum += a(n);
return sum;
}
console.log(4 * summation(0, 100000000, n => (n & 1 === 1 ? -1 : 1) / (2 * n + 1))); // 3.141592663589326
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment