Complex class final

A Dart representation of a complex number in the form a + bi where a is the real part and bi is the imaginary (or complex) part.

A Complex object is immutable.

Implemented types

Constructors

Complex(double real, double imaginary)
Creates a complex number with the given real and imaginary parts.
const
Complex.fromFraction(Fraction real, Fraction imaginary)
Creates a complex number from Fraction objects.
factory
Complex.fromImaginary(double imaginary)
Creates a complex with only the imaginary part.
const
Complex.fromImaginaryFraction(Fraction imaginary)
Creates a complex number having only the imaginary part expressed as a Fraction object.
factory
Complex.fromImaginaryMixedFraction(MixedFraction imaginary)
Creates a complex number having only the imaginary part expressed as a MixedFraction object.
factory
Complex.fromMixedFraction(MixedFraction real, MixedFraction imag)
Creates a complex number from MixedFraction objects.
factory
Complex.fromPolar({required double r, required double theta, bool angleInRadians = true})
Creates a complex number from the given polar coordinates where r is the radius and theta is the angle.
factory
Complex.fromReal(double real)
Creates a complex with only the real part.
const
Complex.fromRealFraction(Fraction real)
Creates a complex number having only the real part expressed as a Fraction object.
factory
Complex.fromRealMixedFraction(MixedFraction real)
Creates a complex number having only the real part expressed as a MixedFraction object.
factory
Complex.i()
This is the same as calling Complex(0, 1).
const
Complex.zero()
This is the same as calling Complex(0, 0).
const

Properties

hashCode int
The hash code for this object.
no setteroverride
imaginary double
The imaginary part of the complex number.
final
isZero bool
Checks whether the complex number is zero.
no setter
negate Complex
The sign of the current object is changed and the result is returned in a new Complex instance.
no setter
real double
The real part of the complex number.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() double
Computes the square root of (a2 + b2) where a is the real part and b is the imaginary part.
compareTo(Complex other) int
Compares this object to another object.
override
conjugate() Complex
The sign of the imaginary part of current object is changed and the result is returned in a new Complex instance.
copyWith({double? real, double? imaginary}) Complex
Creates a deep copy of this object and replaces (if non-null) the given values with the old ones.
cos() Complex
Calculates the cosine of this complex number.
cot() Complex
Calculates the cotangent of this complex number.
exp() Complex
Calculates the base-e exponential of a complex number z where e is the Euler constant.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
nthRoot(int nth) Complex
Computes the complex n-th root of this object. The returned root is the one with the smallest positive argument.
phase() double
Converts rectangular coordinates to polar coordinates by computing an arc tangent of y/x in the range from -pi to pi.
pow(num x) Complex
Calculates the power having a complex number as base and a real value as exponent. The expression is in the form (a + bi)x.
reciprocal() Complex
Finds the multiplicative inverse (reciprocal) of the current instance and returns the result in a new Complex object.
sin() Complex
Calculates the sine of this complex number.
sqrt() Complex
Calculates the square root of this complex number.
tan() Complex
Calculates the tangent of this complex number.
toPolarCoordinates() PolarComplex
Converts this object into polar coordinates and wraps them in a new PolarComplex object.
toString() String
A string representation of this object.
override
toStringAsFixed(int fractionDigits) String
Prints the real and the imaginary parts of this Complex object with fractionDigits decimal digits. The output produced by this method is the same that would result in calling toStringAsFixed on a double:
toStringAsFraction() String
Prints the real and the imaginary parts of the complex number as fractions with the best possible approximation.
toStringWithParenthesis() String
Prints the complex number with opening and closing parenthesis in case the complex number had both real and imaginary part.

Operators

operator *(Complex other) Complex
The products of two complex numbers.
operator +(Complex other) Complex
Sums two complex numbers.
operator -(Complex other) Complex
Subtracts two complex numbers.
operator /(Complex other) Complex
Divides two complex numbers.
operator <(Complex other) bool
There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
operator <=(Complex other) bool
There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
operator ==(Object other) bool
The equality operator.
override
operator >(Complex other) bool
There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
operator >=(Complex other) bool
There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
operator unary-() Complex
Returns the negation of this complex number.