On Nov 3, 2009, at 06:18, 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?

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?

Clearly you cannot *directly calculate* a value correct to hundreds of significant digits unless you can *represent* the value correct to hundreds of significant digits.

Clearly long double and NSDecimal cannot represent that many significant digits.

Therefore you cannot do this with a direct implementation of the Brent- Salamin algorithm. You're going to have to do one of:

1. Come up with your own representation of the value, correct to the desired number of significant digits, and write math routines for adding, subtracting, multiplying, dividing and taking square roots of numbers in your new representation.

or

2. Modify the algorithm so that it produces the digits sequentially without relying on high precision.

Both of those sound extremely difficult, at least if you want an execution time shorter than your lifetime.

I really don't think Cocoa has anything that can help you here. It's a pure computer science project.


_______________________________________________

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