CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Pi Calculator

  1. #1
    Join Date
    Oct 2009
    Posts
    15

    Pi Calculator

    I'm writing a program that calculates Pi in C and i'm using a double data structure to store the final result. Double only gives me a certain amount of digits after the decimal point. My question is, what kind of data structure or what method could I use if I potentially wanted to have it calculate 100 digits or more after the decimal point?

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Pi Calculator

    You need a package for arbitrary-precision arithmetics,

    http://en.wikipedia.org/wiki/Arbitra...ion_arithmetic

  3. #3
    Join Date
    May 2002
    Posts
    1,435

    Re: Pi Calculator

    If your need is to simply determine the digits in PI and not use this extended precision number in any calculations, then all you need is an algorithm. Sorry that I can't suggest one, but a Google search should turn up several sources - or maybe someone here could recommend one.

    To clarify: the extended precision digits could be stored in an array of integers or as ASCII characters in a string. Obviously, if stored this way you would not be able to use the value in any calculations.

  4. #4
    Join Date
    Oct 2009
    Posts
    15

    Re: Pi Calculator

    Thx for the inputs. I'll look into arbitrary precision arithmetic.

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Pi Calculator

    gmp is a common and easy to use one.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured