Calculate $\pi$ in an arbitrary base, to arbitrary precision

1.8k Views Asked by At

I need to calculate $\pi$ -- in base: 4, 12, 32, and 128 -- to an arbitrary number of digits. (It's for an artist friend).

I remember Taylor series and I've found miscellaneous "BBP" formulas, but so far, nothing that points to calculating the digits in arbitrary bases.

How can this be done in a practical manner?

2

There are 2 best solutions below

1
On BEST ANSWER

There is a celebrated formula (perhaps BBP?) that allows you to calculate an arbitrary hexadecimal digit of the expansion of $\pi$. That takes care of bases $4,32,128$.

Now any other formula that is used to calculate $\pi$ in decimal, actually calculates $\pi$ in binary, the result being converted to decimal using the simple base-conversion algorithm. So you can use any old formula, say the arc-tangent one.

Finally, there's probably somewhere on the web an expansion of $\pi$ to zillions of binary digits. Moreover, someone probably wrote a program that converts from binary to an arbitrary base. So all you need to do is find these and plug them together.

3
On

There are many algorithms that can calculate pi, or alternatively there are many sufficiently accurate approximates of pi (to what might as well be arbitrarily many decimal places). I think the easiest way would just be to take the known value and covert it with a method of base conversion, rather than calculate it independently in each.