operator / method

Complex operator /(
  1. Complex other
)

Divides this complex number by other.

Uses the formula (a + bi) / (c + di) = ((ac + bd) + (bc - ad)i) / (c² + d²).

Throws a StateError if other has zero magnitude (division by zero).

Implementation

Complex operator /(Complex other) {
  final denominator = other.norm();
  if (denominator == 0.0) {
    throw StateError('Division by zero in Complex arithmetic.');
  }
  return Complex(
    (_real * other._real + _imag * other._imag) / denominator,
    (_imag * other._real - _real * other._imag) / denominator,
  );
}