Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/website: Has incorrect value for Pi calculated #53598

Open
elpamyelhsa opened this issue Jun 29, 2022 · 3 comments · May be fixed by golang/website#165
Open

x/website: Has incorrect value for Pi calculated #53598

elpamyelhsa opened this issue Jun 29, 2022 · 3 comments · May be fixed by golang/website#165
Labels
NeedsInvestigation website
Milestone

Comments

@elpamyelhsa
Copy link

@elpamyelhsa elpamyelhsa commented Jun 29, 2022

What is the URL of the page with the issue?

https://go.dev/

What is your user agent?

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

Screenshot

image

What did you do?

Select "Concurrent pi" from the Try Go dropdown list

What did you expect to see?

3.14159265358979

What did you see instead?

3.141392653591791

Getting math correct is really important, 3.14139 should be 3.14159. While this example is supposed to present an approximation of Pi, I would not consider this an approximate value if 15 decimal places are being quoted.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 29, 2022

Change https://go.dev/cl/414826 mentions this issue: _content/doc/play: use the Nilakantha Series to compute pi

@ZekeLu
Copy link

@ZekeLu ZekeLu commented Jun 29, 2022

Interesting! Though the purpose is to show the amazing use case of goroutine and channel, I think it makes sense to choose another implementation that gets a better result in the while.

Here is the updated demo: https://go.dev/play/p/aeA0HwfYiBz

@robpike
Copy link
Contributor

@robpike robpike commented Jun 29, 2022

P.S. This remarkable algorithm was found by a machine, and proven by mathematicians.

Here is the ivy version, including a pointer to a relevant paper.

# A much more efficient version found by PSLQ. See Nature, Vol 590, page 69.
op PSLQpiTerm N = (/16**N)* (4 / 1+8*N)-(2 / 4+8*N)+(/5+8*N)+(/6+8*N)
op PSLQpi N = +/PSLQpiTerm -1 + iota N

Not what you want here for the Go site, as it converges ridiculously fast and requires bignums, but it is indeed remarkable. You get one hex digit of precision per iteration.

PSLQpi 1
3.13333333333

PSLQpi 2
3.14142246642

PSLQpi 3
3.14158739035

PSLQpi 4 
3.14159245757

PSLQpi 5
3.14159264546

PSLQpi 6
3.14159265323

PSLQpi 7
3.14159265357

Couldn't resist.

@dr2chase dr2chase added the NeedsInvestigation label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation website
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants