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.




rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem 	CADDI/CADDR  addition of complex numbers  Z1 + Z2    with Z1 = a1 + b1 *i   Z2 = a2 + b2*i
rem                CADDI returns imaginary part and CADDR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub caddi( a1 , b1 , a2 , b2)
    return (b1 + b2)
end sub
export sub caddr( a1 , b1 , a2 , b2)
    return (a1 + a2)
end sub
 
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CDIVI/CDIVR  division of complex numbers  Z1 / Z2        with Z1 = r + s *i   Z2 = t + u*i
rem                CDIVI returns imaginary part and CDIVR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub cdivi(r,s,t,u)
    return ((s*t- u*r) / (t^2 + u^2))
end sub
export sub cdivr( r , s , t , u)
    return ((r*t- s*u) / (t^2 + u^2))
end sub
 
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CMULI/CMULR  multiplication of complex numbers  Z1 * Z2, with Z1 = r + s *i   Z2 = t + u*i
rem                CMULI returns imaginary part and CMULR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub cmuli( r , s , t , u)
    return (r * u + s * t)
end sub
export sub cmulr( r , s , t , u)
    return (r * t - s * u)
end sub
 
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CSUBI/CSUBR  subtraction of complex numbers Z1 - Z2  with Z1 = a1 + b1 *i   Z2 = a2 + b2*i
rem                CSUBI returns imaginary part and CSUBR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub csubi( a1 , b1 , a2 , b2)
    return (b1 - b2)
end sub
export sub csubr( a1 , b1 , a2 , b2)
    return (a1 - a2)
end sub
 
if (peek$("library") = "main") then
    print "Example: Z1 + Z2 with Z1 = 3 +2i , Z2 = 1-3i: Z1 + Z2 = 4 -1i"
    print caddr(3,2,1,-2), "/", caddi(3,2,1,-3)   //   4/-1
end if