Thread: Value of Pie Problem

  1. #16
    Registered User
    Join Date
    Mar 2010
    Location
    pkr
    Posts
    32
    Thanks for the solution.
    But what header file and what data type will make me print this to 1000 decimal places.
    just i want "what header file and which data type" please help me
    Code:
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
        int n;
        cout << setprecision (100) << (12*atan(1.0/49) + 32*atan(1.0/57) - 5*atan(1.0/239) + 12*atan(1.0/110443))*4;
    	cin >> n;
        return 0;
    }

  2. #17
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Option 1: As already mentioned, use an arbitrary precision math library.

    Option 2: There are algorithms for calculating pi digit by digit. E.g one implementation found here (computes 800 digits, code unfortunately obfuscated to take less space):

    Code:
    #include <cstdio>
    int a=10000,b,c=2800,d,e,f[2801],g;
    
    int main()
    {
        for(;b-c;)
            f[b++]=a/5;
        for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
            for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #18
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    You might be interested in this: GNU MP Pi computation

    The code's in C, but you could still learn from it. GMP is a good bignum lib, it has a C++, interface if you're interested.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem on - Selection on which item to purchase
    By karipap in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 06:19 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM