operator / method
Division
Implementation
Complex operator /(Object other) {
if (other is Complex) {
final double denominator =
other.real * other.real + other.imaginary * other.imaginary;
if (denominator == 0) {
throw ArgumentError('Division by zero');
}
return Complex(
(real * other.real + imaginary * other.imaginary) / denominator,
(imaginary * other.real - real * other.imaginary) / denominator,
);
} else if (other is num) {
if (other == 0) {
throw ArgumentError('Division by zero');
}
return Complex(real / other, imaginary / other);
}
throw ArgumentError('Cannot divide Complex by ${other.runtimeType}');
}