
PROGRAM CMPXTEST;
{To test CMPXLIB library for complex arithmetic}

TYPE
  COMPLEX = RECORD RE,IM:REAL
END;

TYPE
  PHASOR = RECORD MAG,ANG:REAL
END;

VAR X1,X2,ANS:COMPLEX;
    OPR:CHAR;
    V1,VANS:PHASOR;
    ANGLE:REAL;

EXTERNAL PROCEDURE CMPX(N1:COMPLEX;OP:CHAR;N2:COMPLEX;VAR CRES:COMPLEX);
EXTERNAL PROCEDURE POLAR(N:COMPLEX;VAR VECT:PHASOR);
EXTERNAL PROCEDURE CART(N:PHASOR;VAR XY:COMPLEX);
EXTERNAL PROCEDURE CSQR(N:COMPLEX;VAR CSQ:COMPLEX);
EXTERNAL PROCEDURE CSQRT(N:COMPLEX;VAR CSQT:COMPLEX);
EXTERNAL PROCEDURE CONJG(N:COMPLEX;VAR CONJ:COMPLEX);
EXTERNAL FUNCTION CABS(N:COMPLEX):REAL;
BEGIN
REPEAT
  WRITELN('Enter complex number, arithmetic operator, complex number');
  READ(X1.RE,X1.IM,OPR,X2.RE,X2.IM);
  CMPX(X1,OPR,X2,ANS);	    
  WRITELN('Answer = ',ANS.RE:6:2,' j  ',ANS.IM:6:2);
UNTIL OPR='Q';

  WRITE('Enter complex number : ');
  READ(X1.RE,X1.IM);
  POLAR(X1,VANS);
  ANGLE:=VANS.ANG/1.74533E-02; {Convert radians to degrees}
  WRITELN('Polar = ',VANS.MAG:8:3,' at ',ANGLE:8:3);

  CART(VANS,ANS);
  WRITELN('Back to Cartesian = ',ANS.RE:8:3,'  j  ',ANS.IM:8:3);

  CSQR(X1,ANS);
  WRITELN('SQUARE=',ANS.RE:8:4,ANS.IM:8:4);

  CSQRT(X1,ANS);
  WRITELN('SQUARE ROOT=',ANS.RE:7:3,ANS.IM:7:3);

  CONJG(X1,ANS);
  WRITELN('Conjugate=',ANS.RE:7:3,ANS.IM:7:3);

  WRITELN('Absolute value=',CABS(X1):10:6);
END.
:3);

  CONJG(X1,