#include //next four are standard for GENPREC #include #include #include #include //include when doing disk file operations #include //need this when timing (benchmarking) const int precision = 8; const int zmaxsize=51; //for declarations const int cmaxsize=0; #include "genprec.h" //User main starts here main() {int i,j,k; double x; //not used in examples below realmp a,b,c,h,zpi; zsuppi(); //run this if pi is needed (trig and inverse trig) zsupe(); //run this if e is needed zsuplogsp(); //run this when exp and log functions required cout<<" "<<'\n'; //space cout<<"A number of calculations using genprec.h are made in order to test it."<<'\n'; cout<<"You should print the source code and follow it as the example executes "<<'\n'; cout<<"because the source code contains comments not printed to the screen."<<'\n'; cout<<"You should devise further tests."<<'\n'; cout<<" "<<'\n'; cout<<"If you are going to use pi a lot, store it."<<'\n'; cout<<"The line of code zpi=pi_mp(); will now be executed"<<'\n'; zpi=pi_mp(); printmp(zpi); zmessage="That was the result of printmp(zpi) after setting zpi=pi_mp()"; zbreak(); //examples of file operations in C++ a=3; //write to myfile a=sqrt(a); printmp(a); zmessage="sqrt(3) will be written to myfile.dat"; cerr << zmessage <<'\n'; writetofile(a,"myfile.dat"); a=2; //just a filler to change a before next a=sqrt(a); //opening of myfile printmp(a); zmessage="sqrt(2) calculation changes registers before reopening myfile.dat."; cerr << zmessage <<'\n'; readfromfile(a,"myfile.dat"); printmp(a); zmessage="sqrt(3) loaded from myfile.dat."; zbreak(); zinput[precision+1]=2; //This means + (- is 0) zinput[precision]=3141; zinput[precision-1]=5926; zinput[precision-2]=5358; zinput[precision-3]=9793; zinput[precision-4]=2384; zinput[0]=1; //note exp shift not included here a