#include //these four files standard for GENPREC #include //abs (absolute value) #include //log,sqrt,etc #include //use when timing (benchmarking) const int precision=4; const int zmaxsize=51; //51; const int cmaxsize=0; float hfloat; int qqq; #include "genprec.h" realmp a,aa,b,bb,aaa,bbb,aaaa,bbbb,c,d,e,f,g,h,sum; realmp vec[zmaxsizepad],vec2[zmaxsizepad]; realmp mat[zmaxsizepad][zmaxsizepad],mat2[zmaxsizepad][zmaxsizepad]; char *zwhich; main() {int i; zsuppi(); //this has to be run to do sin,cos,etc. zsupe(); zsuplogsp(); //for exponential function unsigned int ii; cout<<"This example tests simple arithmetical operations which mix "<<'\n'; cout<<"realmp numbers, floating point numbers, and signed and unsigned "<<'\n'; zmessage="integers in multi-precision calculations. "; zbreak(); for (ii=0;ii<11;ii++) {a=ii; printmp(a); } zmessage="result of realmp a=ii for unsigned int ii=0 to 10" ; zbreak(); a=2; printmp(a); zmessage="result of setting realmp a=2 "; zbreak(); for (ii=0;ii<11;ii++) {b=a*ii; printmp(b); } zmessage="result of realmp b=a*ii for unsigned int ii=0 to 10"; zbreak(); for (ii=0;ii<11;ii++) {b=a/ii; printmp(b); } cout<<"same for b=a/ii"<<'\n'; cout<<"Note that in genprec division by 0 results in 0 with no error messages"<<'\n'; zmessage="which is correct because the principal value of a/0 is 0."; zbreak(); for (ii=0;ii<11;ii++) {b=ii*a; printmp(b); } zmessage="same for b=ii*a"; zbreak(); for (ii=0;ii<11;ii++) {b=ii+a; printmp(b); } zmessage="same for b=ii+a"; zbreak(); for (ii=0;ii<11;ii++) {b=a+ii; printmp(b); } zmessage="same for b=a+ii"; zbreak(); int j; for (j=-5;j<6;j++) {a=j; //these are ok printmp(a); } zmessage="result of real mp a=j for int j=-5 to 5"; zbreak(); a=2; printmp(a); zmessage="result of resetting realmp a=2 "; zbreak(); for (j=-5;j<6;j++) {b=a*j; printmp(b); } zmessage="result of realmp b=a*j for int j=-5 to 5"; zbreak(); for (j=-5;j<6;j++) {b=a/j; printmp(b); } zmessage="same for b=a/j"; zbreak(); for (j=-5;j<6;j++) {b=j*a; printmp(b); } zmessage="same for b=j*a"; zbreak(); for (j=-5;j<6;j++) {b=j/a; printmp(b); } zmessage="same for b=j/a"; zbreak(); for (j=-5;j<6;j++) {b=j+a; printmp(b); } zmessage="same for b=j+a"; zbreak(); for (j=-5;j<6;j++) {b=a+j; printmp(b); } zmessage="same for b=a+j"; zbreak(); b=a+2; //here, is 2 signed or unsigned? cout<<"result of realmp b=a+2"<<'\n'; //no matter! printmp(b); zmessage=" "; zbreak(); b=2+a; cout<<"result of realmp b=2+a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=a-2; cout<<"result of realmp b=a-2"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=2-a; cout<<"result of realmp b=2-a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=a*2; //here, is 2 signed or unsigned? cout<<"result of realmp b=a*2"<<'\n'; //no matter! printmp(b); zmessage=" "; zbreak(); b=2*a; cout<<"result of realmp b=2*a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=-2*a; cout<<"result of realmp b=-2*a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=-a*2; cout<<"result of realmp b=-a*2"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=a/2; //here, is 2 signed or unsigned? cout<<"result of realmp b=a/2"<<'\n'; //no matter! printmp(b); zmessage=" "; zbreak(); b=2/a; cout<<"result of realmp b=2/a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=-2/a; cout<<"result of realmp b=-2/a"<<'\n'; printmp(b); zmessage=" "; zbreak(); b=a/(-2); cout<<"result of realmp b=a/(-2)"<<'\n'; printmp(b); zmessage=" "; zbreak(); a=1.5E00; //this is ok cout<<"result of setting realmp a=1.5E00 "; printmp(a); a=-1.5E00; cout<<"result of setting realmp a=-1.5E00: "; printmp(a); a=3/2; cout<<"The result of setting realmp a=3/2 is incorrect: "; printmp(a); zmessage="The reason: 3/2 is integer divide which is 1. "; zbreak(); a=1.5E00; b=4 + a; cout<<"result of realmp b=4+a for a=1.5E00 which should be 5.5:"<<'\n'; printmp(b); zmessage=" "; zbreak(); a=1; b=floattomp(4.0E00)+a; cout<<"result of b=floattomp(4.0E00)+a for realmp a=1 (should be 5.0):"<<'\n'; printmp(b); zmessage=" "; zbreak(); return 0; }