operator / method
Divide two complex number
References
- "Python Division Of Complex Numbers Without Using Built In Types and Operators". https://stackoverflow.com/a/41146661/6846888. Retrieved 2019-07-15.
Examples
var c1 = Complex(real: 1, imaginary: -3);
var c2 = Complex(real: 1, imaginary: 2);
print(c1 / c2);
/* output:
Complex(real: -1.0, imaginary: -1.0)
*/
Implementation
Complex operator /(Complex b) {
var conjugation = complexConjugate(b);
var denominatorRes = b * conjugation;
// denominator has only real part
var denominator = denominatorRes.real;
var nominator = this * conjugation;
return Complex(
real: nominator.real / denominator,
imaginary: nominator.imaginary / denominator);
}