Reputation: 163
How do I calculate the nth binary (or hexadecimal) digit of pi using the Bailey–Borwein–Plouffe formula? I have been thoroughly searching the Internet and this site for an answer, but I've still yet to find an actual implementation for the algorithm.
The Bailey–Borwein–Plouffe page on Wikipedia tells me that "The method calculates the nth digit without calculating the first n − 1
digits, and can use small, efficient data types". The problem is, the page only explains the formula in this form:
Pi = SUM k=0 to infinity ...
But I have no clue how to use this information to actually find the nth digit of pi. (You know, I don't want to find the value of Pi itself, nor do I want to count a sum to infinity...) I just need to see an example in any programming language or pseudo-code on how to do this in practice.
int nthDigitOfPi(long n) {
// calculate and return the n-th binary digit of pi
// ...
}
Thanks in advance. Your help will be greatly appreciated.
Upvotes: 12
Views: 8022
Reputation:
Hey this website has a solution in python, archive.org link
I am currently trying it in php which I will post if it works ever. To clarify, did you also want the BBP solution to calculate pi?
Upvotes: 1