Complex<T extends num, E extends num> constructor

Complex<T extends num, E extends num>([
  1. T? real,
  2. E? imaginary
])

Initializing a complex number

The first parameter is the real number and second is the imaginary part It can be instantiate with no parameters that equals to 0+0i of type num Example:

final c1 = Complex(7, 5.5);
final c2 = Complex();
final c3 = Complex(5);

Implementation

factory Complex([T? real, E? imaginary]) {
  final r = real ?? (T == double ? 0.0 : 0) as T;
  final i = imaginary ?? (E == double ? 0.0 : 0) as E;
  return Complex._(r, i);
}