operator - method

  1. @override
Cartesian operator -(
  1. Object subtrahend
)
override

Returns a Complex whose value is this - subtrahend. Uses the definitional formula

(a + bi) - (c + di) = (a-c) + (b-d)i

If either this or subtrahend has a NaN value in either part, nan is returned; otherwise infinite and NaN values are returned in the parts of the result according to the rules for double arithmetic.

Implementation

@override
Cartesian operator -(Object subtrahend) {
  if (subtrahend is Cartesian) {
    if (isNaN || subtrahend.isNaN) {
      return Complex.nan;
    }

    return Cartesian(
        real - subtrahend.real, imaginary - subtrahend.imaginary);
  } else if (subtrahend is num) {
    if (isNaN || subtrahend.isNaN) {
      return Complex.nan;
    }
    return Cartesian(real - subtrahend, imaginary);
  } else {
    throw ArgumentError('factor must be a num or a Complex');
  }
}