cast method

  1. @override
Complex cast(
  1. dynamic value
)
override

Casts the argument to this data type, otherwise throw an ArgumentError.

Implementation

@override
Complex cast(dynamic value) {
  if (value is Complex) {
    return value;
  } else if (value is num) {
    return Complex(value);
  } else if (value is BigInt) {
    return Complex(value.toDouble());
  } else if (value is Fraction) {
    return Complex(value.toDouble());
  } else if (value is String) {
    return Complex.tryParse(value) ?? super.cast(value);
  }
  return super.cast(value);
}