reciprocal method

Complex reciprocal()

Finds the multiplicative inverse (reciprocal) of the current instance and returns the result in a new Complex object.

If you let z be a complex in the standard form of z = a + bi then the reciprocal is 1/z, which can also be written as:

  • 1 / (a + bi)
  • (x - yi) / (x2 + y2)
  • conj(a + bi) / modulo(a + bi)2

Implementation

Complex reciprocal() {
  if (isZero) {
    throw const ComplexException('The reciprocal of zero is undefined.');
  }

  final scale = real * real + imaginary * imaginary;

  return Complex(real / scale, -imaginary / scale);
}