tags:

views:

435

answers:

4
+1  A: 

Wikipedia details a lot of ways to get numerical approximations of pi here. They also give some sample pseudo-code

Edit : If you're interested in this kind of mathematical problems without having any related real-world problem to solve (which is definitely a good attitude to have, IMHO), you could visit the Euler Project page

Brann
Sorry, you misread my question. I'm not after anything within the range of native types. I want true "BigNum" π.
Bent Rasmussen
I'm also not after a "baked" solution, just genuine input/ideas about this. I didn't think I was the only person on Stackoverflow to be interested in this kind of thing in my spare time.
Bent Rasmussen
@Bent. This is a classic math problem. It's covered extensively in the wikipedia page I posted, and I honestly doubt you will get some guenuinely new ideas here. What exactly are you after ?
Brann
Don't get hung up over the term "approximation." Any representation, even one that is arbitrarily (not infinitely) precise, is still a numerical approximation.
Jimmy
I agree with that Jimmy but I still think using the term infinite is acceptable given that streams do in fact model infinite series, even if they can never be realized. But it doesn't really matter. I think .Net lacks a "native" BigReal type (one that comes with the BCL).
Bent Rasmussen
+2  A: 

There exists such possibility to process big rational numbers in DLR-based dynamic languages (e.g. IronPython). Or you can use any portable C/C++ implementation of big real numbers through P/Invoke.

macropas
+4  A: 
sth
Thanks a lot! This exactly the kind of stuff I was looking for!
Bent Rasmussen
+2  A: 

By far my favorite Haskell spigot for pi comes from Jeremy Gibbons:

pi = g(1,0,1,1,3,3) where
    g(q,r,t,k,n,l) = 
        if 4*q+r-t<n*t
        then n : g(10*q,10*(r-n*t),t,k,div(10*(3*q+r))t-10*n,l)
        else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)

The mathematical background that justifies that implementation can be found in:

A Spigot Algorithm for the Digits of Pi

Edward Kmett
Awesome! Thanks for the reference!
Bent Rasmussen