Thursday, March 14, 2024

Pi: A Million Digits of Pi in 9 Lines of Javascript

A Million Digits of Pi in 9 Lines of Javascript

A Million Digits of Pi in 9 Lines of JavaScript | Hacker News

ajennings.net/pi.html

let i = 1n;
let x = 3n * (10n ** 1020n);
let pi = x;
while (x > 0) {
        x = x * i / ((i + 1n) * 4n);
        pi += x / (i + 2n);
        i += 2n;
}
console.log(pi / (10n ** 20n));

No comments: