+ 1

how to get upto 1000 digit of pi

math module of python only gave me upto 15 digits import math idx = int(input()) pi = str(math.pi).split(".")[1] print(pi[idx]) //digit at given decimal index

19th Nov 2022, 3:25 AM
Sunil Shrestha
Sunil Shrestha - avatar
3 Antworten
+ 4
Ρέυμα thanks for the input. I still think that computing the precise digits is rather challenging, even if you are ever so familiar with trigonometry (which I am apparently not). It took me quite a few days to develop this code after trying to understand the algorithm in the paper of Rabinowitz and Wagon (1995) https://www.maa.org/sites/default/files/pdf/pubs/amm_supplements/Monthly_Reference_12.pdf But I'm sure you can do better than that ;) I really admire you if this sounds like an easy problem for you. https://code.sololearn.com/c9VmNZWaDL1s/?ref=app
19th Nov 2022, 2:55 PM
Tibor Santa
Tibor Santa - avatar
+ 3
from sympy import pi print(pi.evalf(1000)) If you want to calculate the digits on your own, that can get you involved with very deep math, but some resources for you to check. https://en.m.wikipedia.org/wiki/Approximations_of_%CF%80 https://en.m.wikipedia.org/wiki/Spigot_algorithm
19th Nov 2022, 7:33 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Ρέυμα thank you for clarifying your point and in theory you're right, this should be a simple concept. But the real complexity comes from the problem that computers store numbers in a small finite space, and approximating the actual digits is quite tricky in most modern programming languages. Maybe there are a few out there which specialize on math features such as lim, but I am not familiar with them. https://reference.wolfram.com/language/ref/Pi.html?view=all This article mentions that a modern computer could compute a million digits of PI in a fraction of seconds, using the Chudnowsky formula. But when I look at the description of this algorithm, it looks pretty daunting and I have no immediate idea how I could put it into code... https://en.m.wikipedia.org/wiki/Chudnovsky_algorithm
20th Nov 2022, 3:46 AM
Tibor Santa
Tibor Santa - avatar