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.




with Ada.Numerics.Generic_Complex_Types;
with Ada.Text_IO.Complex_IO;
 
procedure Complex_Operations is
   -- Ada provides a pre-defined generic package for complex types
   -- That package contains definitions for composition,
   -- negation, addition, subtraction, multiplication, division,
   -- conjugation, exponentiation, and absolute value, as well as
   -- basic comparison operations.
   -- Ada provides a second pre-defined package for sin, cos, tan, cot,
   -- arcsin, arccos, arctan, arccot, and the hyperbolic versions of 
   -- those trigonometric functions.
 
   -- The package Ada.Numerics.Generic_Complex_Types requires definition
   -- with the real type to be used in the complex type definition.
 
   package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Long_Float);
   use Complex_Types;
   package Complex_IO is new Ada.Text_IO.Complex_IO (Complex_Types);
   use Complex_IO;
   use Ada.Text_IO;
 
   A : Complex := Compose_From_Cartesian (Re => 1.0, Im => 1.0);
   B : Complex := Compose_From_Polar (Modulus => 1.0, Argument => 3.14159);
   C : Complex;
 
begin
   -- Addition
   C := A + B;
   Put("A + B = "); Put(C);
   New_Line;
   -- Multiplication
   C := A * B;
   Put("A * B = "); Put(C);
   New_Line;
   -- Inversion
   C := 1.0 / A;
   Put("1.0 / A = "); Put(C);
   New_Line;
   -- Negation
   C := -A;
   Put("-A = "); Put(C);
   New_Line;
   -- Conjugation
   Put("Conjugate(-A) = ");
   C := Conjugate (C); Put(C);
end Complex_Operations;