On 04/11/2009, at 1:18 AM, Ian Piper wrote:

I am writing an implementation of the Brent-Salamin algorithm for calculating pi. I want to be able to display potentially a large number of decimal places in the result (hundreds at least). However I am finding that even using long double values in my calculation gives me only the first 50 or so decimal places. Is this a limitation of long double that I am running into here?

Yes, remarkably enough, something of finite size has limits on its precision.

Should I be using NSDecimal instead to do this kind of calculation? If so, can anyone point me at a good example of its use as I am struggling with how to use it?

NSDecimal may help, but it's also of finite size, so it won't help trying to print out the digits of pi to arbitrary precision, since pi is infinitely long. Algorithms to print the digits of pi usually emit the digits one at a time, so they are not storing the whole value as a single number. You'll probably need to resort to this sort of approach if you're just trying to calculate pi. To use the resulting value of pi in a calculation is going to be very difficult, and probably serves no practical purpose.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to