6
$\begingroup$

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?

  • 0
    @DJC, We're currently using a million (decimal). But the plan is for as many as it takes or that works best.2011-04-30

3 Answers 3

5

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.

1

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.

  • 0
    yes. The main problem is efficiency. (1) having to store potentially billions of digits, (2) for each new base we want to test, then having to convert all umpteen million preceding digits to get to the digits of interest.     Such an approach may work, given cheap processors and memory, but it is inelegant and I will save it as a last-ish resort.       Finally, the question *as stated* is an interesting problem, IMO, and I thought for sure it would already have been solved; it doesn't seem that difficult.2011-04-30
1

Usually, ye calculate pi, and then convert it into the target base.

   3:16E8 E212,7796 7998,5967 5292,6847 6661,9725 5723         base 120    3.141 592 653,589 793 238,462 643 383,279 502 884,197       base 10 

This is an implementation in rexx, that finds pi to so many digits in decimal, base 120, and any named base.

  • 0
    @BrockAdams Bases 4, 32, a$n$d 128 can be derived from a hexadecimal source, since all of these are groupings of binary digits. Base 12 is different. REXX calculates in decimal, the conversion done above is to 30 places, but is a conversion of the decimal, increased by some smallish fraction to prevent .333333 turning up as .39E9 E9E9 E9E9, rather than .4000 0000 0000.2013-05-17