DEV Community

Discussion on: TIL: Calculating n digits of pi using Chudnovsky Algorithm

Collapse
 
tigersharks profile image
TigerSharks • Edited

This result does not seem correct. I think the first 39 digits of pi are:

3.14159265358979323846264338327950288420

This does not agree with your result,

3.14159265358974158651772731545786503578
000000000000000^
Difference starts here. Sorry, I did not debug your code. I'm new to Python and wrote this program as an exercise. My results are different and agree with what's published for pi online.

Also, you don't need to compute n-1 loops of the Chudnovsky series to get n digits of precision. To compute 30 digits of precision (31 total) you only need to compute Sigma 4 times -- that includes the freebie you get to start at k=0.

It's clear that something is wrong with your code because your 30th position is a 9, but the 30th position in the 301 digit calculation is a 7. It's not possible to round a 7 to a 9.

I'm curious what went wrong.

Collapse
 
vsierrajc profile image
Juan Carlos Sierra

I check the pi value using the benchmark software SUPER_PI_MOD-1.5 and i get pi with four millions digits
PI=3.1415926535 8979323846 2643383279 5028841971 6939937510
5820974944 5923078164 0628620899 8628034825 3421170679
8214808651 3282306647 0938446095 5058223172 5359408128
4811174502 8410270193 8521105559 6446229489 5493038196
4428810975 6659334461 2847564823 3786783165 2712019091
the first result is correct

Collapse
 
tigersharks profile image
TigerSharks • Edited

In the original post, Parambir shows the output for 30 and 300 digits of pi. It's in the code block right after the "Here's the CLI in action:"

./pi.py 30
3.141592653589741586517727315459

./pi.py 300
3.1415926535897415865177273154578650357802526912....

The results as shown in the author's work are wrong, and don't agree with your results.