Complex<T> Structure

Represents a generic complex value.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.4
C#
[SerializableAttribute]
public readonly struct Complex<T> : IEquatable<Complex<T>>, 
	IEquatable<T>, IComparable<Complex<T>>, INumberBase<Complex<T>>, 
	IFormattable, IParsable<Complex<T>>, ISpanFormattable, ISpanParsable<Complex<T>>, 
	IUtf8SpanFormattable, IUtf8SpanParsable<Complex<T>>, IAdditionOperators<Complex<T>, Complex<T>, Complex<T>>, 
	IAdditiveIdentity<Complex<T>, Complex<T>>, IDecrementOperators<Complex<T>>, 
	IDivisionOperators<Complex<T>, Complex<T>, Complex<T>>, IEqualityOperators<Complex<T>, Complex<T>, bool>, 
	IIncrementOperators<Complex<T>>, IMultiplicativeIdentity<Complex<T>, Complex<T>>, 
	IMultiplyOperators<Complex<T>, Complex<T>, Complex<T>>, ISubtractionOperators<Complex<T>, Complex<T>, Complex<T>>, 
	IUnaryNegationOperators<Complex<T>, Complex<T>>, IUnaryPlusOperators<Complex<T>, Complex<T>>
Inheritance
Object  →  ValueType  →  Complex<T>
Implements
IComparable<Complex<T>>, IEquatable<Complex<T>>, IEquatable<T>, IFormattable, IParsable<Complex<T>>, ISpanFormattable, ISpanParsable<Complex<T>>, IUtf8SpanFormattable, IUtf8SpanParsable<Complex<T>>, IAdditionOperators<Complex<T>, Complex<T>, Complex<T>>, IAdditiveIdentity<Complex<T>, Complex<T>>, IDecrementOperators<Complex<T>>, IDivisionOperators<Complex<T>, Complex<T>, Complex<T>>, IEqualityOperators<Complex<T>, Complex<T>, Boolean>, IIncrementOperators<Complex<T>>, IMultiplicativeIdentity<Complex<T>, Complex<T>>, IMultiplyOperators<Complex<T>, Complex<T>, Complex<T>>, INumberBase<Complex<T>>, ISubtractionOperators<Complex<T>, Complex<T>, Complex<T>>, IUnaryNegationOperators<Complex<T>, Complex<T>>, IUnaryPlusOperators<Complex<T>, Complex<T>>

Type Parameters

T

Remarks

The complex value type represents a complex value made of real and imaginary parts of type T.

Complex numbers arise in algebra in the solution of quadratic equations. The equation

C#
<i>x</i><sup>2</sup> = -1
does not have any real solutions. However, if we define a new number, i as the square root of
C#
#8211;1
, then we have two solutions: i and -i.

This, in turn, gives rise to an entirely new class of numbers of the form a + ib with a and b real, and i defined as above. These are the complex numbers.

The complex structure provides methods for all the common operations on complex numbers. The Re property returns the real element of the complex number, while Im returns the imaginary part. Because the complex numbers don't have a natural ordering, only equality and inequality operators are available.

Overloaded versions of the major arithmetic operators are provided for languages that support them. For languages that don't support operator overloading, equivalent static methods are supplied.

When performing binary operations, if one of the operands is a complex, then the other operand is required to be either of type complex or . Prior to performing the operation, if the other operand is not a complex, it is converted to complex. If the operation produces a numeric result, the type of the result is complex.

Exceptions to this are methods that return a real property of a complex number: Phase, Magnitude, MagnitudeSquared and Abs(Complex<T>). These methods return a T value.

If T is a floating-point type, then operations including the assignment operators, do not throw exceptions. Instead, in exceptional situations, the result of a floating-point operation is zero, Infinity, or NaN, as described below:

  • If the result of a complex floating-point operation is too small for the destination format, the result of the operation is zero.
  • If the magnitude of the complex result of a floating-point operation is too large for the destination format, the result of the operation is Infinity. Directed infinities are currently not supported.
  • If a complex floating-point operation is invalid, the result of the operation is NaN.
  • If one or both operands of a complex floating-point operation are NaN, the result of the operation is NaN.
.

Many elementary functions have been extended to the complex domain. These are implemented by static methods.

Some of these functions are multi-valued. If there is one real argument, then any symmetry or anti-symmetry about the origin is preserved. For example, the inverse sine function satisfies asin(-x) == -asin(x) for -1 <= x <= 1. The Asin(Complex<T>) method satisfies this relationship for any real value of x.

For complex arguments, the identity Conjugate(f(x)) == f(Conjugate(x)) is preserved. The branch cuts for all complex functions defined here are along either the real or the imaginary axis. Along the branch cuts, the functions have different values depending on whether the zero element is normal (positive) zero or negative zero.

The real and imaginary parts of complex numbers are real numbers.

Constructors

Complex<T>(T) Constructs a complex number from a real number.
Complex<T>(T, T) Constructs a complex number from its real and imaginary parts.

Properties

Im Gets the imaginary part of the complex number.
IsImaginary Indicates whether a complex number is a pure imaginary number.
IsReal Indicates whether a complex number is, in fact, real.
IsZero Indicates whether a complex number is equal to zero.
Magnitude Gets the magnitude, modulus or absolute value of a complex number.
MagnitudeSquared Returns the square of the modulus of a complex number.
OneNorm Returns the sum of the absolute values of the real and the imaginary part of the complex number.
Phase Gets the phase or argument of a complex number.
Re Gets the real part of the complex number.

Methods

Abs Returns the absolute value of a complex number.
Acos(T) Gets the inverse cosine of a real number.
Acos(Complex<T>) Gets the inverse cosine of a complex number.
Acosh Gets the inverse hyperbolic cosine of a complex number.
Add(T, Complex<T>) Adds a complex number to a real number.
Add(Complex<T>, T) Adds a complex number to a real number.
Add(Complex<T>, Complex<T>) Adds two complex numbers.
Arg Returns the argument of a complex number.
Asin(T) Gets the inverse sine of a real number.
Asin(Complex<T>) Gets the inverse sine of a complex number.
Asinh Gets the inverse hyperbolic sine of a complex number.
Atan Gets the inverse tangent of a complex number.
Atanh Gets the inverse hyperbolic tangent of a complex number.
Cbrt Returns the first square root of a complex number.
Conjugate() Returns the conjugate of this complex number.
Conjugate(Complex<T>) Returns the conjugate of a complex number.
ConjugateMultiply Multiplies the Conjugate() of a complex number and a second complex number.
Cos Gets the cosine of a complex number.
Cosh Gets the hyperbolic cosine of a complex number.
Deconstruct Deconstructs a complex number into its real and complex parts.
Decrement Decrements the real part of a complex number by one.
Divide(T, Complex<T>) Divides a real number by a complex number.
Divide(Complex<T>, T) Divides a complex number by a real number.
Divide(Complex<T>, Complex<T>) Divides a complex number by another.
Equals(T) Compares a complex number to a real number.
Equals(Complex<T>) Compares a complex number to another complex number.
Equals(Object) Overridden. Returns whether this instance is equal to a specified object.
(Overrides ValueType.Equals(Object))
Exp Returns e raised to the specified power.
Exp10 Returns 10 raised to the specified power.
Exp2 Returns 2 raised to the specified power.
ExpI Evaluates the exponential function for an imaginary argument.
ExpM1 Computes E raised to a given power and subtracts one.
FromPolar Constructs a complex number from polar elements.
GetHashCode Overridden. Returns the hash code for this instance.
(Overrides ValueType.GetHashCode())
GetImaginaryPart Returns an array of Doubles that contains the imaginary parts of an array of complex numbers.
GetRealPart Returns an array of Doubles that contains the real parts of an array of complex numbers.
GetTypeGets the Type of the current instance.
(Inherited from Object)
Imaginary Constructs a complex number that has a purely imaginary value.
Increment Increments the real part of a complex number by one.
IsInfinity Indicates whether a complex number is infinite.
IsNaN Indicates whether a complex number is undefined.
Log(Complex<T>) Returns the natural logarithm of a complex number.
Log(Complex<T>, Complex<T>) Returns the logarithm of a complex number to the specified base.
Log10 Returns the base 10 logarithm of a complex number.
Log2 Returns the base 2 logarithm of a complex number.
Multiply(T, Complex<T>) Multiplies a complex number and a real number.
Multiply(Complex<T>, T) Multiplies a complex number and a real number.
Multiply(Complex<T>, Complex<T>) Multiplies two complex numbers.
Negate Negates a complex number.
Parse(ReadOnlySpan<Char>, IFormatProvider)Parses a span of characters into a value.
Parse(String, IFormatProvider)Parses a string into a value.
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)Parses a span of characters into a value.
Parse(String, NumberStyles, IFormatProvider)Parses a string into a value.
Plus Applies the unary plus operator to a complex number.
Pow(Complex<T>, T) Returns a complex number raised to the specified power.
Pow(Complex<T>, Complex<T>) Returns a complex number raised to the specified power.
Pow(Complex<T>, Int32) Returns a complex number raised to the specified integer power.
Reciprocal Returns the reciprocal of a complex number.
RootOfUnity Returns a complex number that is the specified root of unity of the specified degree.
Sin Gets the sine of a complex number.
SinCos Gets the sine and cosine of a complex number.
Sinh Gets the hyperbolic sine of a complex number.
Sqrt(T) Returns the first square root of a real number.
Sqrt(Complex<T>) Returns the first square root of a complex number.
Subtract(T, Complex<T>) Subtracts a complex number from a real number.
Subtract(Complex<T>, T) Subtracts a real number from a complex number.
Subtract(Complex<T>, Complex<T>) Subtracts two complex numbers.
Tan Gets the tangent of a complex number.
Tanh Gets the hyperbolic tangent of a complex number.
ToString() Converts the numeric value of this instance to its equivalent string representation.
(Overrides ValueType.ToString())
ToString(IFormatProvider) Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
ToString(String) Converts the numeric value of this instance to its equivalent string representation using the specified format.
ToString(String, IFormatProvider) Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
TryFormatTries to format the value of the current instance into the provided span of characters.
TryParse(ReadOnlySpan<Char>, IFormatProvider, Complex<T>)Tries to parse a span of characters into a value.
TryParse(String, IFormatProvider, Complex<T>)Tries to parse a string into a value.
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Complex<T>)Tries to parse a span of characters into a value.
TryParse(String, NumberStyles, IFormatProvider, Complex<T>)Tries to parse a string into a value.

Operators

Addition(T, Complex<T>) Adds a complex number to a real number.
Addition(Complex<T>, T) Adds a complex number to a real number.
Addition(Complex<T>, Complex<T>) Adds two complex numbers.
Decrement(Complex<T>) Decrements the real part of a complex number by one.
Division(T, Complex<T>) Divides a real number by a complex number.
Division(Complex<T>, T) Divides a complex number by a real number.
Division(Complex<T>, Complex<T>) Divides a complex number by another.
Equality(T, Complex<T>) Compares a complex number and a real number for equality.
Equality(Complex<T>, T) Compares a complex number and a real number for equality.
Equality(Complex<T>, Complex<T>) Compares two complex numbers for equality.
Explicit(Complex<T> to T) Casts a complex number to a real number. The imaginary part must be zero.
Exponent(Complex<T>, T) Represents the exponentiation operator.
Exponent(Complex<T>, Complex<T>) Represents the exponentiation operator.
Exponent(Complex<T>, Int32) Represents the exponentiation operator.
Exponentiation(Complex<T>, T) Represents the exponentiation operator.
Exponentiation(Complex<T>, Complex<T>) Represents the exponentiation operator.
Exponentiation(Complex<T>, Int32) Represents the exponentiation operator.
Implicit(T to Complex<T>) Implicitly casts a real number to a complex type.
Implicit(ValueTuple<T, T> to Complex<T>) Implicitly casts a tuple of two real numbers to a complex type.
Increment(Complex<T>) Increments the real part of a complex number by one.
Inequality(T, Complex<T>) Compares a complex number and a real number for inequality.
Inequality(Complex<T>, T) Compares a complex number and a real number for inequality.
Inequality(Complex<T>, Complex<T>) Compares two complex numbers for inequality.
Multiply(T, Complex<T>) Multiplies a complex number and a real number.
Multiply(Complex<T>, T) Multiplies a complex number and a real number.
Multiply(Complex<T>, Complex<T>) Multiplies two complex numbers.
Subtraction(T, Complex<T>) Subtracts a complex number from a real number.
Subtraction(Complex<T>, T) Subtracts a real number from a complex number.
Subtraction(Complex<T>, Complex<T>) Subtracts two complex numbers.
UnaryNegation(Complex<T>) Negates a complex number.
UnaryPlus(Complex<T>) Applies the unary plus operator to a complex number.

Fields

I Represents the square root of -1.
Infinity Represents complex infinity.
NaN Represents complex NaN, or Not a Number.
One Represents the complex number one.
Zero Represents the complex number zero.

See Also