#include #include #include #include int precision = 8; int zmaxsize=51; //for declarations int cmaxsize=0; #include "genprecd.h" #include "cgnprecd.h" extern declarations(); //a user defined function unsigned int * *a; //declare five complex numbers unsigned int * *b; unsigned int * *c; unsigned int * *d; unsigned int * *ctemp; int i; //and an integer i declarations() //finish declaring the complex numbers (this is an example { //of the user declarations() which should always be a = new unsigned int * [2]; //created and run at the top of main after the b = new unsigned int * [2]; //declarations in the GenPrec tree c = new unsigned int * [2]; d = new unsigned int * [2]; ctemp = new unsigned int * [2]; for (i=0;i<2;i++) {a[i] = new unsigned int [prec+8]; b[i] = new unsigned int [prec+8]; c[i] = new unsigned int [prec+8]; d[i] = new unsigned int [prec+8]; ctemp[i] = new unsigned int [prec+8]; } return 0; } //User main starts here main() { zsuppi(); //need these for trig operations zsupe(); //need these two for log and exp operations zsuplogsp(); declarations(); // goto biele; //check sqrt in rectangular cconinttomp(1,1); //calls 1 + i to the register csqrt(cz); //complex square root of 1 + i in rectangular representation cprnt(cz); zmessage="square root of 1+i in rec"; zbreak(); cmult(cz,cz); cprnt(cz); zmessage="sqrt squared in rec"; zbreak(); //check sqrt in polar cconinttomp(1,1); //calls 1 + i to the register csqrtpol(cz); //complex square root of 1 + i in rectangular representation cprnt(cz); zmessage="square root of 1*exp(i) in polar"; zbreak(); cmultpol(cz,cz); cprnt(cz); zmessage="sqrt squared in pol"; zbreak(); cconinttomp(1,3); //these lines which set up (1 + 3i)/2 ccompconj(cz); cdivint(cz,2); zconinttomp(1); //and this line cannot be interchanged cmultcbyr(cz,z); //because z would not be carried to this line cprnt(cz); zmessage="(.5-1.5i)*1"; zbreak(); cconinttomp(0,2); //see remark above. set up 2i in cz zconinttomp(4); //set up -4 in z zchs(z); cmultcbyr(cz,z); cprnt(cz); zmessage="2i*(-4)"; zbreak(); zconinttomp(1); //a=1+2*i zstore(a[0]); zconinttomp(2); zstore(a[1]); //could have used cconinttomp(1,2);cstore(a); zconinttomp(3); //b=3+4*i zstore(b[0]); zconinttomp(4); zstore(b[1]); //could have used cconinttomp(3,4);cstore(b); cabs(a); //check cabvrec function zprnt(z); zmessage="abs value of a=1+2*i"; zbreak(); ccompconj(a); //check complex conjugate function //notice rectangular specified explicitly cprnt(cz); zmessage="complex conjugate of a"; zbreak(); cadd(a,b); //check the add function //notice rectangular specified explicitly cprnt(cz); //print the result zmessage="a+b (b=3 + 4*i)"; zbreak(); csub(a,b); //check the subtraction function cprnt(cz); zmessage="a-b"; zbreak(); cmult(a,b); //check the multiplication function cprnt(cz); zmessage="a*b"; zbreak(); cdiv(a,b); //check the divide function cprnt(cz); zmessage="a/b"; zbreak(); zconinttomp(2); //check adding a real to a complex in rectangular caddcplusr(a,z); cprnt(cz); zmessage="1+2i (complex) + 2(real)"; zbreak(); crectopol(a); //check conversion from rectangular to polar cprnt(cz); zmessage="mag and phase of a"; zbreak(); cpoltorec(cz); //convert it back again to check conversion from polar cprnt(cz); //to rectangular zmessage="converting that to rectangular should give a back"; zbreak(); ccompconj(a); //convert complex conjugate to crectopol(cz); //polar (should just change sign of theta (the second cprnt(cz); //argument) zmessage="mag and phase of a*"; zbreak(); crecall(a); //-a cchs(cz); crectopol(cz); //change to polar (should make theta = pi-theta cprnt(cz); zmessage="mag and phase of -a"; zbreak(); crectopol(a); //convert a to polar cxtonthpol(cz,3); //cube it cpoltorec(cz); //convert back to rectangular cprnt(cz); zmessage="a^3 from cxtonthpol"; zbreak(); //check of sin,cos from addition formulas //sin(a+b)=sin(a)cos(b)+cos(a)sin(b) //cos(a+b)=cos(a)cos(b)-sin(a)sin(b) cconinttomp(1,1); //calls 1 + i to the register csin(cz); cstore(a); //sin a cconinttomp(1,1); //calls 1 + i to the register ccos(cz); cstore(b); //cos a cconinttomp(3,4); //calls 3 + 4i to the register csin(cz); cstore(c); //sin b cconinttomp(3,4); //calls 3 + 4 to the register ccos(cz); cstore(d); //cos b cconinttomp(4,5); csin(cz); //sin(a+b) cprnt(cz); zmessage="sin(4,5)"; zbreak(); cmult(a,d); //sin a cos b cstore(ctemp); cmult(b,c); //cos a sin b cadd(cz,ctemp); //add them cprnt(cz); zmessage="same from addition formula for sin"; zbreak(); cconinttomp(4,5); //calls 4 + 5i to the register ccos(cz); cprnt(cz); zmessage="cos(4,5)"; zbreak(); cmult(a,c); cstore(ctemp); cmult(b,d); csub(cz,ctemp); cprnt(cz); zmessage="same from addition formula for cos"; zbreak(); //now check arctan outside unit circle cconinttomp(4,5); csin(cz); cstore(a); cconinttomp(4,5); ccos(cz); cdiv(a,cz); //tan=sin/cos cprnt(cz); zmessage="tan(4+5i)"; zbreak(); carctan(cz); cprnt(cz); zmessage="arctan(tan(4+5i)) should be 4+k*pi+5i"; zbreak(); biele: //now check arctan inside unit circle cconinttomp(4,5); cdivint(cz,10); csin(cz); //cprnt(cz); //zmessage="sin"; //zbreak(); cstore(a); cconinttomp(4,5); cdivint(cz,10); ccos(cz); //cprnt(cz); //zmessage="cos"; //zbreak(); cdiv(a,cz); //tan=sin/cos cprnt(cz); zmessage="tan(.4+.5i)"; zbreak(); carctan(cz); cprnt(cz); zmessage="arctan(tan(.4+.5i)) should be .4+k*pi+.5i"; zbreak(); //now check addition law for exponential in rectangular cconinttomp(1,1); cexp(cz); cstore(a); cconinttomp(3,4); cexp(cz); cstore(b); cconinttomp(4,5); cexp(cz); cprnt(cz); zmessage="e^(4+51) in rec"; zbreak(); cmult(a,b); cprnt(cz); zmessage="e^(1+i)*e^(3+4i)"; zbreak(); //now check addition law for logarithm in rectangular cconinttomp(1,1); cln(cz); cstore(a); cconinttomp(3,4); cln(cz); cstore(b); cconinttomp(1,1); cstore(c); cconinttomp(3,4); cmult(cz,c); cln(cz); cprnt(cz); zmessage="log(a*b)"; zbreak(); cadd(a,b); cprnt(cz); zmessage="loga + log b"; zbreak(); //now check log of pol in rec cconinttomp(3,4); clogpolinrec(cz); //log is log3 + 4i cprnt(cz); zmessage="log(3*exp(4i)"; zbreak(); cexp(cz); crectopol(cz); cprnt(cz); //should be 3+4i zmessage="should be 3+4i"; zbreak(); return 0; }