A   complex number   is a number which can be written as:




a
+
b
×
i


{\displaystyle a+b\times i}


(sometimes shown as:




b
+
a
×
i


{\displaystyle b+a\times i}


where   



a


{\displaystyle a}

   and   



b


{\displaystyle b}

  are real numbers,   and   



i


{\displaystyle i}

   is   √ -1 



Typically, complex numbers are represented as a pair of real numbers called the "imaginary part" and "real part",   where the imaginary part is the number to be multiplied by 



i


{\displaystyle i}

.



Task

 Show addition, multiplication, negation, and inversion of complex numbers in separate functions. (Subtraction and division operations can be made with pairs of these operations.) 
 Print the results for each operation tested.
 Optional: Show complex conjugation.


By definition, the   complex conjugate   of




a
+
b
i


{\displaystyle a+bi}


is




a
−
b
i


{\displaystyle a-bi}





Some languages have complex number libraries available.   If your language does, show the operations.   If your language does not, also show the definition of this type.




include c:\cxpl\codes;
 
func real CAdd(A, B, C);        \Return complex sum of two complex numbers
real A, B, C;
[C(0):= A(0) + B(0);
 C(1):= A(1) + B(1);
return C;
];
 
func real CMul(A, B, C);        \Return complex product of two complex numbers
real A, B, C;
[C(0):= A(0)*B(0) - A(1)*B(1);
 C(1):= A(1)*B(0) + A(0)*B(1);
return C;
];
 
func real CNeg(A, C);           \Return negative of a complex number
real A, C;
[C(0):= -A(0);
 C(1):= -A(1);
return C;
];
 
func real CInv(A, C);           \Return inversion (reciprical) of complex number
real A, C;
real D;
[D:= sq(A(0)) + sq(A(1));
C(0):= A(0)/D;
C(1):=-A(1)/D;
return C;
];
 
func real Conj(A, C);           \Return conjugate of a complex number
real A, C;
[C(0):= A(0);
 C(1):=-A(1);
return C;
];
 
proc COut(D, A);                \Output a complex number to specified device
int D; real A;
[RlOut(D, A(0));
  Text(D, if A(1)>=0.0 then " +" else " -");
 RlOut(D, abs(A(1)));
ChOut(D, ^i);
];
 
real U, V, W(2);
[Format(2,2);
U:= [1.0,  1.0];
V:= [3.14, 1.2];
COut(0, CAdd(U,V,W)); CrLf(0);
COut(0, CMul(U,V,W)); CrLf(0);
COut(0, CNeg(U,W));   CrLf(0);
COut(0, CInv(U,W));   CrLf(0);
COut(0, Conj(U,W));   CrLf(0);
]