I wrote a utility that's supposed to calculate pi, but running it with a number of loops over about 20 causes it to return NAN, and anything below that returns 37-point-something. It's based off of the Chudnovsky algorithm, at http://en.wikipedia.org/wiki/Chudnovsky_algorithm . I think I may have copied the algorithm incorectly, or maybe it has something to do with the fact that I didn't account for the 12 to the left of the sigma. What does that mean, anyway?
Another thing is it uses doubles. Is there some kind of infinite (or at least very high) precision data type that I can just replace all the doubles with without having to make a whole bunch of changes? I tried GMP's mpf_t, but it doesn't even support the standard +, -, *, / or = operators. Is there something I can use that does?
Your algorithm is fine if you account for the 12. You must multiply the sum by 12 before taking the inverse. If I exclude the 12, then the first convergent is approx. 37.69911184. With it I get approx. 3.14159265.