• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Handling calculations with many decimal places
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling calculations with many decimal places


  • Subject: Re: Handling calculations with many decimal places
  • From: Graham Cox <email@hidden>
  • Date: Wed, 4 Nov 2009 01:29:17 +1100


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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Handling calculations with many decimal places
      • From: Graham Cox <email@hidden>
References: 
 >Handling calculations with many decimal places (From: Ian Piper <email@hidden>)

  • Prev by Date: Handling calculations with many decimal places
  • Next by Date: Re: Overriding -[UIViewController loadView], and loading from a nib
  • Previous by thread: Handling calculations with many decimal places
  • Next by thread: Re: Handling calculations with many decimal places
  • Index(es):
    • Date
    • Thread