Arbitrary Precision for C++ Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bsmath
    New Member
    • Mar 2010
    • 7

    Arbitrary Precision for C++ Program

    I am trying to achieve arbitrary precision for the C++ program below. It works
    only to about two digits (integer 50) on the C++ compiler I used a few days ago.
    I am trying to implement the MAPM arbitrary precision library for 300000000
    (three hundred million) digits. Any other method or precision greater than
    200000 (two hundred thousand) digits will be helpful, but the one below is
    best, unless a better method can be found. I did not know what to do with the
    last few lines (if(int(X/Y)==X/N)cout<<"yes";
    else cout<<"no";
    cout<<"\tS: "<<S<<"\tR: "<<R<<"\ta: "<<a<<endl; ) as far as
    arbitrary precision goes.


    Code:
    #include<iostream>
    #include<cmath>
    #include<"m_apm.h">
    using namespace std;
     
    int main()
    {
         m_apm_cpp_precision(300000000);
        double a_mapm=m_apm_2.0,m_apm_R=1;
        for(int S=900;S<913;S+=2)
        {
            double N_mapm=m_apmpow(2,R)*S+1;
            double X_mapm=m_apmpow(a,S)-1;
            double Y_mapm=m_mapmpow(2,R)*S+1;
            if(int(X/Y)==X/N)cout<<"yes";
            else cout<<"no";
          cout<<"\tS: "<<S<<"\tR: "<<R<<"\ta: "<<a<<endl;      
          }
    char q;
    cout<<"press enter to delete screen...";
    cin.get(q);
    return 0;
    }
    Last edited by Niheel; May 24 '10, 07:25 PM. Reason: added code tags
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    Hmm you say you are trying to set precision to 300 000 000.
    Ok I have no idea how to do that although the people evaluating pi have gone a lot further on the Cray. However you cannot write the double pow (double, double) as above with that prefix in C++ to evaluate 2 raised to power R as far as I am aware irrespective of what is in the header file of the same name.Will follow with interest.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      A double has only 15 digits. A float has 6.

      You cannot use floating pointer for accuracy. Floating point is designed specifically for scientific wiork where extreme accuracy is not required.

      In your case you will need to write a large number library if you can't find one already written that you can buy.

      Comment

      Working...