Live data from Hacker News

A Million Digits of Pi in 9 Lines of JavaScript

ajennings.net

11–20 of 86 posts

Re: A Million Digits of Pi in 9 Lines of JavaScript

#11
post #3

Wow, I wonder why Firefox is so much slower? Quantum seems pretty zippy overall, but maybe that's largely due to fast rendering speeds? Does anyone on the Spidermonkey team have some insight?

What is benchmarked here is basically the performance of the division operation on big integers and does not represent the general performance of a browser for everyday tasks.

Re: A Million Digits of Pi in 9 Lines of JavaScript

#12
A fun related thread on math stackexchange which has several examples of series which converge quickly to pi: https://math.stackexchange.com/questions/14113/series-that-c...

edit: There also some nice formulae for quick convergence in this article: https://julialang.org/blog/2017/03/piday

Re: A Million Digits of Pi in 9 Lines of JavaScript

#13
> this simple one still converges at about 0.6 decimal digits per term.

Quick proof of this: as the number of terms n in the sum goes to infinity, the ratio of each term to the previous one is approximately 1/4 - the first factor contributes m/(m+1), the second q/(q+2) for some m and q that go to infinity along with n, the third contributes 1/4.

If we counted base 4, then the value of each digit would be on average 1/4 of the previous one, certainly for a normal number like pi. But we count base 10, so we get log_10 4 decimal digits every time we get one base-four digit. Which is very close to 0.6.

Re: A Million Digits of Pi in 9 Lines of JavaScript

#18

On any standard unix system with bc installed - it's preinstalled on most of them, you can calculate pi to $n digits using bc: bc -l <<< "scale=$n; 4*a(1)"

The algorithm seems to be at least quadratic in the length. On a 2014 i7 Mac mini, (n, time(sec)) = (1000, 0.29), (2000, 1.65), (4000, 9.70), (8000, 58.42).

Re: A Million Digits of Pi in 9 Lines of JavaScript

#19

JS Error `No identifiers allowed directly after numeric literal` when running http://ajennings.net/pi.html on Mac OS Mojave 10.14.6, Safari 12.1.2 (14607.3.9)

Safari does not support BigInt yet it seems.

Safari seems to be consistently behind these days, not sure why.

Re: A Million Digits of Pi in 9 Lines of JavaScript

#20

Earlier quoted context omitted.

Safari does not support BigInt yet it seems.

Safari seems to be consistently behind these days, not sure why.

Apple seems to be the only browser developer that makes user-centric changes first, not developer-centric.

I'm OK with that.

Post reply on HN