unit Cmplx; interface uses math; type complex = record re,im: extended; end; function abs (a:complex):extended; function arg (a:complex):extended; function conj (a:complex):complex; function add (a,b:complex):complex; function sub (a,b:complex):complex; function mult (a,b:complex):complex; function divi (a,b:complex):complex; function csqrt (a:complex):complex; function pow (a:complex; b: extended):complex; overload; function pow ( a:complex; b: complex) : complex; overload; function csin (a:complex):complex; function ccos (a:complex):complex; function ctan (a:complex):complex; implementation function abs (a:complex):extended; begin abs:=sqrt(Sqr(a.re)+Sqr(a.im)); end; function arg (a:complex):extended; begin if a.re<>0 then arg:=arctan(a.im/a.re) else if a.im>0 then arg:=pi/2 else arg:=-pi/2; end; function conj (a:complex):complex; begin conj.re:=a.re; conj.im:=-a.im; end; function add (a,b:complex):complex; begin add.re:=a.re + b.re; add.im:=a.im + b.im; end; function sub (a,b:complex):complex; begin sub.re:=a.re - b.re; sub.im:=a.im - b.im; end; function mult (a,b:complex):complex; begin mult.re:=a.re*b.re - a.im*b.im; mult.im:=a.im*b.re + b.im*a.re; end; function divi (a,b:complex):complex; var k:extended; begin k:=b.re*b.re+b.im*b.im; if (k=0) then {write cannot divide by zero} else begin divi.re:=(a.re*b.re + a.im*b.im)/k; divi.im:=(a.im*b.re - a.re*b.im)/k; end; end; function csqrt (a:complex):complex; var j,k:extended; begin k:=arg(a)/2; j:=sqrt(abs(a)); csqrt.re:=j*cos(k); csqrt.im:=j*sin(k); end; function pow (a:complex; b: extended):complex; overload; var j,k:extended; begin k:=arg(a)*b; j:=Power(abs(a),b); pow.re:=j*cos(k); pow.im:=j*sin(k); end; function pow ( a:complex; b: complex) : complex; overload; Begin End; function csin (a:complex):complex; begin csin.re:=sin(a.re)*cosh(a.im); csin.im:=cos(a.re)*sinh(a.im); end; function ccos (a:complex):complex; begin ccos.re:=cos(a.re)*cosh(a.im); ccos.im:=-sin(a.re)*sinh(a.im); end; function ctan (a:complex):complex; begin ctan:=divi(csin(a),ccos(a)); end; end.