operator * method
Returns the product of this Number and the multiplicand
(a Number or num).
This Number is unaffected.
Implementation
@override
Number operator *(dynamic multiplicand) {
// i * i = -1
if (multiplicand is num) {
return Number.simplifyType(Complex(real * multiplicand as Real,
Imaginary(imaginary.value * multiplicand)));
}
if (multiplicand is Real) {
return Number.simplifyType(Complex(multiplicand * real as Real,
Imaginary(multiplicand * imaginary.value)));
}
if (multiplicand is Imaginary) {
// (0+bi)(c+di)=(-bd)+i(bc)
return Number.simplifyType(Complex(
imaginary.value * multiplicand.value * -1 as Real,
Imaginary(multiplicand.value * real)));
}
if (multiplicand is Complex) {
// (a+bi)(c+di)=(ac-bd)+i(ad+bc)
return Number.simplifyType(Complex(
real * multiplicand.real -
imaginary.value * multiplicand.imaginary.value as Real,
Imaginary(real * multiplicand.imaginary.value +
imaginary.value * multiplicand.real)));
}
// Treat multiplier as zero
return Number.simplifyType(Integer.zero);
}