|


Program to Find N-digits of PiDate: 9/11/96 at 11:4:15 From: Anonymous Subject: Program to Find N-digits of Pi Do you know where I can find C code for doing N-digit decimal arithmetic in C? I want to encode Euler's iterative formula for approximating pi, n=1 sum(1/n^2) -> (pi^2)/6 as n -> inf But if I use unsigned longs, the max n is 65536 because 65536^2 == 2^32. 65536 terms gives you a pretty fair approximation (6 digits worth, or so), but it gets that in about a decisecond on my pentium- 120; I want an iterative algorithm I can run for DAYS. So obviously I'll need to store my numbers in strings, limited only by my RAM. I've written N-digit arithmetic, (just finished division last night, that was tough!) but it only uses whole numbers (division will generate a real, but currently can't use reals for the divisor or dividend (yet). I tried it, but since I'm storing the numbers from LSB to MSB in the string, I ended up just making a big mess. If there's code out there that already does this, I'd love to get my hands on it. Gack
Date: 9/12/96 at 0:39:3
From: Doctor Pete
Subject: Re: Program to Find N-digits of Pi
I know this isn't quite what you're asking for, but there are series
expressions that converge to pi *much* faster than the one you gave.
Similar to yours, the formula
Sum[1/n^4,{n,1,Infinity}] = Pi^4/90
is also true, and is slightly faster. Incidentally, there is an
infinite family of such series; i.e.,
Sum[1/n^(2k),{n,1,Infinity}] = Pi^(2k)*P/Q,
for positive integers P, Q, which derives from the properties of the
Riemann zeta function.
Even faster are series based on arctangent formulae, such as
4*Sum[(-1)^n/((2n+1)*5^(2n+1)),{n,0,Infinity}]
-Sum[(-1)^n/((2n+1)*239^(2n+1)),{n,0,Infinity}] = Pi/4.
Incredibly fast are some series by Ramanujan; i.e.,
(Sqrt[8]/9801)*Sum[(4n)!*(1103+26390n)/((n!)^4*396^(4n)),
{n,0,Infinity}] = 1/Pi .
Regarding your question, there do exist arbitrary precision libraries,
I believe, on the net. Try a web search.
If you want to know more about the series expressions I mentioned
here, as well as additional formulae, visit the following site:
http://pauillac.inria.fr/algo/bsolve/constant/pi/pi.html
-Doctor Pete, The Math Forum
Check out our web site! http://mathforum.org/dr.math/
|
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]


Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/