Table of Contents

Complex<T> Struct

Definition

Namespace
Bodu.Numerics
Assembly
Bodu.Numerics.dll
Package
Bodu.Numerics 1.0.0
Source
Complex{T}.Arithmetic.cs

Represents an immutable complex number - a value with a real and an imaginary component - backed by an arbitrary IFloatingPointIeee754<TSelf> component type.

public readonly struct Complex<T> : ISignedNumber<Complex<T>>, INumberBase<Complex<T>>, IEquatable<Complex<T>>, ISpanFormattable, IFormattable, ISpanParsable<Complex<T>>, IParsable<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>> where T : IFloatingPointIeee754<T>

Type Parameters

T

The floating-point type used to store the real and imaginary components.

Implements
Inherited Members
Extension Methods

Examples

// Construct from components and from polar coordinates.
Complex<double> a = new Complex<double>(3.0, 4.0);      // 3 + 4i
Complex<double> b = Complex<double>.FromPolarCoordinates(5.0, 0.0);

// Arithmetic through the operators.
Complex<double> sum = a + b;                            // 8 + 4i
double magnitude = a.Magnitude;                         // 5

// Parse and format round-trip through the "<real; imaginary>" form.
Complex<double> parsed = Complex<double>.Parse("<1; 2>", null);
string text = parsed.ToString();                        // "<1; 2>"

Remarks

A Complex<T> generalizes the Complex value type, which is fixed to double components, to any IEEE 754 floating-point type. Choose float or Half for compact storage, double for the widest hardware-accelerated range, or another conforming type as required.

The arithmetic mirrors Complex exactly, including its handling of the non-finite values NaN and the infinities: multiplication uses the direct four-multiply form without infinity recovery, division uses Smith's algorithm, and Reciprocal(Complex<T>) of zero returns Zero rather than an infinity.

Because a type parameter cannot carry an implicit conversion from each built-in real type the way Complex does, only the implicit conversion from T (embedding a real value on the real axis) is provided; use Create(T, T), the INumberBase<TSelf> conversion helpers, or FromPolarCoordinates(T, T) for other sources.

Constructors

Complex(T, T)

Initializes a new instance of the Complex<T> struct with the specified real and imaginary components.

public Complex(T real, T imaginary)

Parameters

real T

The real component.

imaginary T

The imaginary component.

Properties

Imaginary

Gets the imaginary component of the complex value.

public T Imaginary { get; }

Property Value

T

The imaginary component.

ImaginaryOne

Gets a Complex<T> representing the imaginary unit.

public static Complex<T> ImaginaryOne { get; }

Property Value

Complex<T>

The complex value 0 + 1i.

Infinity

Gets a Complex<T> whose real and imaginary components are both PositiveInfinity.

public static Complex<T> Infinity { get; }

Property Value

Complex<T>

The complex value ∞ + ∞·i.

Magnitude

Gets the magnitude (absolute value) of the complex value.

public T Magnitude { get; }

Property Value

T

The Euclidean distance of the value from the origin, sqrt(Real² + Imaginary²), computed with overflow- and underflow-avoiding scaling.

NaN

Gets a Complex<T> whose real and imaginary components are both NaN.

public static Complex<T> NaN { get; }

Property Value

Complex<T>

The complex value NaN + NaN·i.

Phase

Gets the phase (argument) of the complex value.

public T Phase { get; }

Property Value

T

The angle in radians from the positive real axis, in the range (-π, π].

Real

Gets the real component of the complex value.

public T Real { get; }

Property Value

T

The real component.

Methods

Abs(Complex<T>)

Returns the magnitude (absolute value) of a complex value.

public static T Abs(Complex<T> value)

Parameters

value Complex<T>

The value whose magnitude is computed.

Returns

T

The Euclidean distance of value from the origin.

Remarks

The magnitude is evaluated with overflow- and underflow-avoiding scaling: the larger component is factored out so that Real² + Imaginary² is never formed directly. This matches the scaled hypotenuse used by Abs(Complex).

Acos(Complex<T>)

Returns the inverse cosine (arccosine) of a complex value.

public static Complex<T> Acos(Complex<T> value)

Parameters

value Complex<T>

The value whose inverse cosine is computed.

Returns

Complex<T>

The principal inverse cosine of value, with branch cuts along the real axis outside [-1, 1].

Remarks

Evaluated with the Hull-Fairgrieve-Tang algorithm shared with Acos(Complex), so the result, including the placement of the branch cut, matches the framework value.

Add(Complex<T>, Complex<T>)

Adds two complex values.

public static Complex<T> Add(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first value.

right Complex<T>

The second value.

Returns

Complex<T>

The sum of left and right.

Asin(Complex<T>)

Returns the inverse sine (arcsine) of a complex value.

public static Complex<T> Asin(Complex<T> value)

Parameters

value Complex<T>

The value whose inverse sine is computed.

Returns

Complex<T>

The principal inverse sine of value, with branch cuts along the real axis outside [-1, 1].

Remarks

Evaluated with the overflow- and cancellation-avoiding algorithm of Hull, Fairgrieve, and Tang - the same scheme Asin(Complex) uses - so the result, including the placement of the branch cut, matches the framework value.

Atan(Complex<T>)

Returns the inverse tangent (arctangent) of a complex value.

public static Complex<T> Atan(Complex<T> value)

Parameters

value Complex<T>

The value whose inverse tangent is computed.

Returns

Complex<T>

The principal inverse tangent of value, with branch cuts along the imaginary axis outside [-i, i].

Remarks

Evaluated as (i/2) · (log(1 − i·value) − log(1 + i·value)), the same closed form Atan(Complex) uses, so the result agrees with the framework value to within floating-point tolerance.

Conjugate(Complex<T>)

Returns the complex conjugate of a value.

public static Complex<T> Conjugate(Complex<T> value)

Parameters

value Complex<T>

The value to conjugate.

Returns

Complex<T>

The value with the sign of its imaginary component reversed.

Cos(Complex<T>)

Returns the cosine of a complex value.

public static Complex<T> Cos(Complex<T> value)

Parameters

value Complex<T>

The value whose cosine is computed.

Returns

Complex<T>

The cosine of value.

Cosh(Complex<T>)

Returns the hyperbolic cosine of a complex value.

public static Complex<T> Cosh(Complex<T> value)

Parameters

value Complex<T>

The value whose hyperbolic cosine is computed.

Returns

Complex<T>

The hyperbolic cosine of value.

Create(T, T)

Creates a Complex<T> from the specified real and imaginary components.

public static Complex<T> Create(T real, T imaginary)

Parameters

real T

The real component.

imaginary T

The imaginary component.

Returns

Complex<T>

A complex value with the specified components.

Deconstruct(out T, out T)

Deconstructs the complex value into its real and imaginary components.

public void Deconstruct(out T real, out T imaginary)

Parameters

real T

When this method returns, contains the real component.

imaginary T

When this method returns, contains the imaginary component.

Divide(Complex<T>, Complex<T>)

Divides one complex value by another.

public static Complex<T> Divide(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The dividend.

right Complex<T>

The divisor.

Returns

Complex<T>

The quotient left divided by right.

Equals(Complex<T>)

Determines whether the specified Complex<T> is equal to this value.

public bool Equals(Complex<T> other)

Parameters

other Complex<T>

The value to compare with this value.

Returns

bool

true if both components are equal under IEquatable<T> equality; otherwise, false.

Remarks

Unlike operator ==(Complex<T>, Complex<T>), this method uses the components' own Equals(object) contract, so a NaN component is considered equal to another NaN component. This matches Equals(Complex).

Equals(object?)

Determines whether the specified object is a Complex<T> equal to this value.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with this value.

Returns

bool

true if obj is a Complex<T> with equal components; otherwise, false.

Exp(Complex<T>)

Returns e raised to the power of a complex value.

public static Complex<T> Exp(Complex<T> value)

Parameters

value Complex<T>

The exponent.

Returns

Complex<T>

The value e^value.

FromPolarCoordinates(T, T)

Creates a Complex<T> from a magnitude and phase expressed in polar coordinates.

public static Complex<T> FromPolarCoordinates(T magnitude, T phase)

Parameters

magnitude T

The distance of the value from the origin.

phase T

The angle, in radians, measured from the positive real axis.

Returns

Complex<T>

The complex value magnitude · (cos(phase) + i·sin(phase)).

GetHashCode()

Returns a hash code for this complex value.

public override int GetHashCode()

Returns

int

A hash code derived from the real and imaginary components.

Log(Complex<T>)

Returns the natural (base e) logarithm of a complex value.

public static Complex<T> Log(Complex<T> value)

Parameters

value Complex<T>

The value whose logarithm is computed.

Returns

Complex<T>

The principal natural logarithm of value.

Log(Complex<T>, T)

Returns the logarithm of a complex value in the specified base.

public static Complex<T> Log(Complex<T> value, T baseValue)

Parameters

value Complex<T>

The value whose logarithm is computed.

baseValue T

The base of the logarithm.

Returns

Complex<T>

The principal logarithm of value in base baseValue.

Log10(Complex<T>)

Returns the base-10 logarithm of a complex value.

public static Complex<T> Log10(Complex<T> value)

Parameters

value Complex<T>

The value whose logarithm is computed.

Returns

Complex<T>

The principal base-10 logarithm of value.

Multiply(Complex<T>, Complex<T>)

Multiplies two complex values.

public static Complex<T> Multiply(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first factor.

right Complex<T>

The second factor.

Returns

Complex<T>

The product left times right.

Negate(Complex<T>)

Returns the additive inverse of a complex value.

public static Complex<T> Negate(Complex<T> value)

Parameters

value Complex<T>

The value to negate.

Returns

Complex<T>

The value with both components negated.

Parse(string)

Parses a string into a Complex<T>.

public static Complex<T> Parse(string s)

Parameters

s string

The string to parse.

Returns

Complex<T>

The complex value the string represents.

Exceptions

ArgumentNullException

Thrown if s is null.

FormatException

Thrown if s is not a valid complex value.

Pow(Complex<T>, Complex<T>)

Returns a complex value raised to a complex power.

public static Complex<T> Pow(Complex<T> value, Complex<T> power)

Parameters

value Complex<T>

The base value.

power Complex<T>

The exponent.

Returns

Complex<T>

The value value^power, using the principal branch of the complex logarithm.

Pow(Complex<T>, T)

Returns a complex value raised to a real power.

public static Complex<T> Pow(Complex<T> value, T power)

Parameters

value Complex<T>

The base value.

power T

The real exponent.

Returns

Complex<T>

The value value^power.

Reciprocal(Complex<T>)

Returns the multiplicative inverse of a complex value.

public static Complex<T> Reciprocal(Complex<T> value)

Parameters

value Complex<T>

The value to invert.

Returns

Complex<T>

The reciprocal 1 / value, or Zero when value is zero.

Remarks

Returning Zero for a zero input matches Reciprocal(Complex) rather than producing an infinity.

Sin(Complex<T>)

Returns the sine of a complex value.

public static Complex<T> Sin(Complex<T> value)

Parameters

value Complex<T>

The value whose sine is computed.

Returns

Complex<T>

The sine of value.

Sinh(Complex<T>)

Returns the hyperbolic sine of a complex value.

public static Complex<T> Sinh(Complex<T> value)

Parameters

value Complex<T>

The value whose hyperbolic sine is computed.

Returns

Complex<T>

The hyperbolic sine of value.

Sqrt(Complex<T>)

Returns the principal square root of a complex value.

public static Complex<T> Sqrt(Complex<T> value)

Parameters

value Complex<T>

The value whose square root is computed.

Returns

Complex<T>

The principal square root, whose real part is non-negative and whose branch cut lies along the negative real axis.

Remarks

The result is evaluated with a symmetry-respecting formula (two real square roots and a division) rather than via polar coordinates, so a purely negative input yields a purely imaginary root and a purely imaginary input yields a root with equal real and imaginary parts. Very large inputs are rescaled to avoid intermediate overflow.

Subtract(Complex<T>, Complex<T>)

Subtracts one complex value from another.

public static Complex<T> Subtract(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The minuend.

right Complex<T>

The subtrahend.

Returns

Complex<T>

The difference left minus right.

Tan(Complex<T>)

Returns the tangent of a complex value.

public static Complex<T> Tan(Complex<T> value)

Parameters

value Complex<T>

The value whose tangent is computed.

Returns

Complex<T>

The tangent of value.

Remarks

Uses the numerically stable double-angle identity, switching to a reciprocal-scaled form for large imaginary components to avoid overflow, matching Tan(Complex).

Tanh(Complex<T>)

Returns the hyperbolic tangent of a complex value.

public static Complex<T> Tanh(Complex<T> value)

Parameters

value Complex<T>

The value whose hyperbolic tangent is computed.

Returns

Complex<T>

The hyperbolic tangent of value.

ToString()

Returns the default string representation of this complex value.

public override string ToString()

Returns

string

The value formatted as <real; imaginary>.

ToString(string?)

Returns a string representation of this complex value, applying the specified format to each component.

public string ToString(string? format)

Parameters

format string

The numeric format specifier applied to the real and imaginary components.

Returns

string

The value formatted as <real; imaginary>.

ToString(string?, IFormatProvider?)

Returns a string representation of this complex value, applying the specified format and culture to each component.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The numeric format specifier applied to the real and imaginary components.

formatProvider IFormatProvider

The culture used to render the numeric components.

Returns

string

The value formatted as <real; imaginary>.

Remarks

The semicolon component separator is fixed regardless of culture so that the format does not collide with the decimal comma used by cultures such as de-DE and fr-FR, matching Complex.

TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)

Attempts to format this complex value into the provided UTF-8 byte span.

public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

utf8Destination Span<byte>

The span that receives the formatted UTF-8 bytes.

bytesWritten int

When this method returns, contains the number of bytes written.

format ReadOnlySpan<char>

The numeric format specifier applied to each component.

provider IFormatProvider

The culture used to render the numeric components.

Returns

bool

true if formatting succeeded; otherwise, false.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Attempts to format this complex value into the provided character span.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>

The span that receives the formatted characters.

charsWritten int

When this method returns, contains the number of characters written.

format ReadOnlySpan<char>

The numeric format specifier applied to each component.

provider IFormatProvider

The culture used to render the numeric components.

Returns

bool

true if formatting succeeded; otherwise, false.

TryParse(string?, out Complex<T>)

Attempts to parse a string into a Complex<T>.

public static bool TryParse(string? s, out Complex<T> result)

Parameters

s string

The string to parse.

result Complex<T>

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

Examples

// Parse the canonical bracketed form and a bare real value.
var z = Complex<double>.Parse("<3; 4>", null);         // 3 + 4i
var real = Complex<double>.Parse("5", null);           // 5 + 0i

// Round-trip: the parsed value formats back to the same canonical text.
string text = z.ToString();                            // "<3; 4>"

Operators

implicit operator Complex<T>(T)

Converts a real value to a Complex<T> by placing it on the real axis.

public static implicit operator Complex<T>(T value)

Parameters

value T

The real value to embed.

Returns

Complex<T>

The complex value value + 0i.

Remarks

This is the generic counterpart of the implicit conversions Complex defines from each built-in real type. A type parameter cannot carry a conversion from every such type, so the single conversion from T is provided; convert other numeric sources with Create(T, T) or the INumberBase<TSelf> conversion helpers first.

Explicit Interface Implementations

IsFinite(Complex<T>)

Determines whether the specified complex number is finite - both its real and imaginary components are finite.

static bool IsFinite(Complex<T> value)

Parameters

value Complex<T>

The complex number to test.

Returns

bool

true when both components are finite; otherwise false.

IsInfinity(Complex<T>)

Determines whether the specified complex number is infinite - either component is an infinity, regardless of the other component's value (including NaN), matching IsInfinity(Complex).

static bool IsInfinity(Complex<T> value)

Parameters

value Complex<T>

The complex number to test.

Returns

bool

true when either component is infinite; otherwise false.

IsNaN(Complex<T>)

Determines whether the specified complex number is NaN - at least one component is NaN and neither component is an infinity, matching IsNaN(Complex) (an infinite component dominates NaN).

static bool IsNaN(Complex<T> value)

Parameters

value Complex<T>

The complex number to test.

Returns

bool

true when the value is NaN; otherwise false.

One

Gets a Complex<T> representing the real unit one.

static Complex<T> One { get; }

Returns

Complex<T>

The complex value 1 + 0i.

Parse(ReadOnlySpan<byte>, IFormatProvider?)

Parses a UTF-8 byte span into a Complex<T> using the specified culture.

static Complex<T> Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)

Parameters

utf8Text ReadOnlySpan<byte>

The UTF-8 encoded text to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

Returns

Complex<T>

The complex value the text represents.

Exceptions

FormatException

utf8Text is not a valid complex-number representation.

Parse(ReadOnlySpan<char>, IFormatProvider?)

Parses a character span into a Complex<T> using the specified culture.

static Complex<T> Parse(ReadOnlySpan<char> s, IFormatProvider? provider)

Parameters

s ReadOnlySpan<char>

The span to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

Returns

Complex<T>

The complex value the span represents.

Exceptions

FormatException

Thrown if s is not a valid complex value.

Parse(string, IFormatProvider?)

Parses a string into a Complex<T> using the specified culture.

static Complex<T> Parse(string s, IFormatProvider? provider)

Parameters

s string

The string to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

Returns

Complex<T>

The complex value the string represents.

Exceptions

ArgumentNullException

Thrown if s is null.

FormatException

Thrown if s is not a valid complex value.

IAdditiveIdentity<Complex<T>, Complex<T>>.AdditiveIdentity

Gets the additive identity of the current type.

static Complex<T> IAdditiveIdentity<Complex<T>, Complex<T>>.AdditiveIdentity { get; }

Returns

Complex<T>

IMultiplicativeIdentity<Complex<T>, Complex<T>>.MultiplicativeIdentity

Gets the multiplicative identity of the current type.

static Complex<T> IMultiplicativeIdentity<Complex<T>, Complex<T>>.MultiplicativeIdentity { get; }

Returns

Complex<T>

INumberBase<Complex<T>>.Abs(Complex<T>)

Computes the absolute of a value.

static Complex<T> INumberBase<Complex<T>>.Abs(Complex<T> value)

Parameters

value Complex<T>

The value for which to get its absolute.

Returns

Complex<T>

The absolute of value.

Exceptions

OverflowException

The absolute of value is not representable by Complex<T>.

INumberBase<Complex<T>>.IsCanonical(Complex<T>)

Determines if a value is in its canonical representation.

static bool INumberBase<Complex<T>>.IsCanonical(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is in its canonical representation; otherwise, false.

INumberBase<Complex<T>>.IsComplexNumber(Complex<T>)

Determines if a value represents a complex number.

static bool INumberBase<Complex<T>>.IsComplexNumber(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is a complex number; otherwise, false.

INumberBase<Complex<T>>.IsEvenInteger(Complex<T>)

Determines if a value represents an even integral number.

static bool INumberBase<Complex<T>>.IsEvenInteger(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is an even integer; otherwise, false.

INumberBase<Complex<T>>.IsImaginaryNumber(Complex<T>)

Determines if a value represents a pure imaginary number.

static bool INumberBase<Complex<T>>.IsImaginaryNumber(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is a pure imaginary number; otherwise, false.

INumberBase<Complex<T>>.IsInteger(Complex<T>)

Determines if a value represents an integral number.

static bool INumberBase<Complex<T>>.IsInteger(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is an integer; otherwise, false.

INumberBase<Complex<T>>.IsNegative(Complex<T>)

Determines if a value represents a negative real number.

static bool INumberBase<Complex<T>>.IsNegative(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value represents negative zero or a negative real number; otherwise, false.

INumberBase<Complex<T>>.IsNegativeInfinity(Complex<T>)

Determines if a value is negative infinity.

static bool INumberBase<Complex<T>>.IsNegativeInfinity(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is negative infinity; otherwise, false.

INumberBase<Complex<T>>.IsNormal(Complex<T>)

Determines if a value is normal.

static bool INumberBase<Complex<T>>.IsNormal(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is normal; otherwise, false.

INumberBase<Complex<T>>.IsOddInteger(Complex<T>)

Determines if a value represents an odd integral number.

static bool INumberBase<Complex<T>>.IsOddInteger(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is an odd integer; otherwise, false.

INumberBase<Complex<T>>.IsPositive(Complex<T>)

Determines if a value represents zero or a positive real number.

static bool INumberBase<Complex<T>>.IsPositive(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value represents (positive) zero or a positive real number; otherwise, false.

INumberBase<Complex<T>>.IsPositiveInfinity(Complex<T>)

Determines if a value is positive infinity.

static bool INumberBase<Complex<T>>.IsPositiveInfinity(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is positive infinity; otherwise, false.

INumberBase<Complex<T>>.IsRealNumber(Complex<T>)

Determines if a value represents a real number.

static bool INumberBase<Complex<T>>.IsRealNumber(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is a real number; otherwise, false.

INumberBase<Complex<T>>.IsSubnormal(Complex<T>)

Determines if a value is subnormal.

static bool INumberBase<Complex<T>>.IsSubnormal(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is subnormal; otherwise, false.

INumberBase<Complex<T>>.IsZero(Complex<T>)

Determines if a value is zero.

static bool INumberBase<Complex<T>>.IsZero(Complex<T> value)

Parameters

value Complex<T>

The value to be checked.

Returns

bool

true if value is zero; otherwise, false.

INumberBase<Complex<T>>.MaxMagnitude(Complex<T>, Complex<T>)

Compares two values to compute which has the greater magnitude.

static Complex<T> INumberBase<Complex<T>>.MaxMagnitude(Complex<T> x, Complex<T> y)

Parameters

x Complex<T>

The value to compare with y.

y Complex<T>

The value to compare with x.

Returns

Complex<T>

x if it has a greater magnitude than y; otherwise, y.

INumberBase<Complex<T>>.MaxMagnitudeNumber(Complex<T>, Complex<T>)

Compares two values to compute which has the greater magnitude and returning the other value if an input is NaN.

static Complex<T> INumberBase<Complex<T>>.MaxMagnitudeNumber(Complex<T> x, Complex<T> y)

Parameters

x Complex<T>

The value to compare with y.

y Complex<T>

The value to compare with x.

Returns

Complex<T>

x if it has a greater magnitude than y; otherwise, y.

INumberBase<Complex<T>>.MinMagnitude(Complex<T>, Complex<T>)

Compares two values to compute which has the lesser magnitude.

static Complex<T> INumberBase<Complex<T>>.MinMagnitude(Complex<T> x, Complex<T> y)

Parameters

x Complex<T>

The value to compare with y.

y Complex<T>

The value to compare with x.

Returns

Complex<T>

x if it has a lesser magnitude than y; otherwise, y.

INumberBase<Complex<T>>.MinMagnitudeNumber(Complex<T>, Complex<T>)

Compares two values to compute which has the lesser magnitude and returning the other value if an input is NaN.

static Complex<T> INumberBase<Complex<T>>.MinMagnitudeNumber(Complex<T> x, Complex<T> y)

Parameters

x Complex<T>

The value to compare with y.

y Complex<T>

The value to compare with x.

Returns

Complex<T>

x if it has a lesser magnitude than y; otherwise, y.

INumberBase<Complex<T>>.Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider)

Parses a span of characters into a value.

static Complex<T> INumberBase<Complex<T>>.Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider)

Parameters

s ReadOnlySpan<char>

The span of characters to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

Returns

Complex<T>

The result of parsing s.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

FormatException

s is not in the correct format.

OverflowException

s is not representable by Complex<T>.

INumberBase<Complex<T>>.Parse(string, NumberStyles, IFormatProvider)

Parses a string into a value.

static Complex<T> INumberBase<Complex<T>>.Parse(string s, NumberStyles style, IFormatProvider provider)

Parameters

s string

The string to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

Returns

Complex<T>

The result of parsing s.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

ArgumentNullException

s is null.

FormatException

s is not in the correct format.

OverflowException

s is not representable by Complex<T>.

INumberBase<Complex<T>>.Radix

Gets the radix, or base, for the type.

static int INumberBase<Complex<T>>.Radix { get; }

Returns

int

INumberBase<Complex<T>>.TryConvertFromChecked<TOther>(TOther, out Complex<T>)

Tries to convert a value to an instance of the the current type, throwing an overflow exception for any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertFromChecked<TOther>(TOther value, out Complex<T> result) where TOther : notnull, INumberBase<TOther>

Parameters

value TOther

The value that's used to create the instance of Complex<T>.

result Complex<T>

When this method returns, contains an instance of Complex<T> converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

Exceptions

OverflowException

value is not representable by Complex<T>.

INumberBase<Complex<T>>.TryConvertFromSaturating<TOther>(TOther, out Complex<T>)

Tries to convert a value to an instance of the the current type, saturating any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertFromSaturating<TOther>(TOther value, out Complex<T> result) where TOther : notnull, INumberBase<TOther>

Parameters

value TOther

The value that is used to create the instance of Complex<T>.

result Complex<T>

When this method returns, contains an instance of Complex<T> converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

INumberBase<Complex<T>>.TryConvertFromTruncating<TOther>(TOther, out Complex<T>)

Tries to convert a value to an instance of the the current type, truncating any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertFromTruncating<TOther>(TOther value, out Complex<T> result) where TOther : notnull, INumberBase<TOther>

Parameters

value TOther

The value that is used to create the instance of Complex<T>.

result Complex<T>

When this method returns, contains an instance of Complex<T> converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type of value.

INumberBase<Complex<T>>.TryConvertToChecked<TOther>(Complex<T>, out TOther)

Tries to convert an instance of the the current type to another type, throwing an overflow exception for any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertToChecked<TOther>(Complex<T> value, out TOther result) where TOther : notnull, INumberBase<TOther>

Parameters

value Complex<T>

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

Exceptions

OverflowException

value is not representable by TOther.

INumberBase<Complex<T>>.TryConvertToSaturating<TOther>(Complex<T>, out TOther)

Tries to convert an instance of the the current type to another type, saturating any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertToSaturating<TOther>(Complex<T> value, out TOther result) where TOther : notnull, INumberBase<TOther>

Parameters

value Complex<T>

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

INumberBase<Complex<T>>.TryConvertToTruncating<TOther>(Complex<T>, out TOther)

Tries to convert an instance of the the current type to another type, truncating any values that fall outside the representable range of the current type.

static bool INumberBase<Complex<T>>.TryConvertToTruncating<TOther>(Complex<T> value, out TOther result) where TOther : notnull, INumberBase<TOther>

Parameters

value Complex<T>

The value that is used to create the instance of TOther.

result TOther

When this method returns, contains an instance of TOther converted from value.

Returns

bool

false if TOther is not supported; otherwise, true.

Type Parameters

TOther

The type to which value should be converted.

INumberBase<Complex<T>>.TryParse(ReadOnlySpan<char>, NumberStyles, IFormatProvider, out Complex<T>)

Tries to parse a span of characters into a value.

static bool INumberBase<Complex<T>>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out Complex<T> result)

Parameters

s ReadOnlySpan<char>

The span of characters to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

result Complex<T>

On return, contains the result of succesfully parsing s or an undefined value on failure.

Returns

bool

true if s was successfully parsed; otherwise, false.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

INumberBase<Complex<T>>.TryParse(string, NumberStyles, IFormatProvider, out Complex<T>)

Tries to parse a string into a value.

static bool INumberBase<Complex<T>>.TryParse(string s, NumberStyles style, IFormatProvider provider, out Complex<T> result)

Parameters

s string

The string to parse.

style NumberStyles

A bitwise combination of number styles that can be present in s.

provider IFormatProvider

An object that provides culture-specific formatting information about s.

result Complex<T>

On return, contains the result of succesfully parsing s or an undefined value on failure.

Returns

bool

true if s was successfully parsed; otherwise, false.

Exceptions

ArgumentException

style is not a supported NumberStyles value.

ISignedNumber<Complex<T>>.NegativeOne

Gets the value -1 for the type.

static Complex<T> ISignedNumber<Complex<T>>.NegativeOne { get; }

Returns

Complex<T>

TryParse(ReadOnlySpan<byte>, IFormatProvider?, out Complex<T>)

Attempts to parse a UTF-8 byte span into a Complex<T> using the specified culture.

static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Complex<T> result)

Parameters

utf8Text ReadOnlySpan<byte>

The UTF-8 encoded text to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

result Complex<T>

When this method returns, contains the parsed value, or the default value on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out Complex<T>)

Attempts to parse a character span into a Complex<T> using the specified culture.

static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Complex<T> result)

Parameters

s ReadOnlySpan<char>

The span to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

result Complex<T>

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

TryParse(string?, IFormatProvider?, out Complex<T>)

Attempts to parse a string into a Complex<T> using the specified culture.

static bool TryParse(string? s, IFormatProvider? provider, out Complex<T> result)

Parameters

s string

The string to parse.

provider IFormatProvider

The culture used to interpret the numeric components.

result Complex<T>

When this method returns, contains the parsed value, or zero on failure.

Returns

bool

true if parsing succeeded; otherwise, false.

Zero

Gets a Complex<T> representing the value zero.

static Complex<T> Zero { get; }

Returns

Complex<T>

The complex value 0 + 0i, which is also default(Complex<T>).

operator +(Complex<T>, Complex<T>)

Adds two complex values.

static Complex<T> operator +(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first value.

right Complex<T>

The second value.

Returns

Complex<T>

The component-wise sum of left and right.

Examples

var a = new Complex<double>(1.0, 2.0);
var b = new Complex<double>(3.0, 4.0);

var sum = a + b;               // 4 + 6i
var difference = a - b;        // -2 - 2i
var product = a * b;           // -5 + 10i
var quotient = a / b;          // 0.44 + 0.08i

operator --(Complex<T>)

Returns the complex value decreased by the real unit one.

static Complex<T> operator --(Complex<T> value)

Parameters

value Complex<T>

The value to decrement.

Returns

Complex<T>

The value with 1 subtracted from its real component.

operator /(Complex<T>, Complex<T>)

Divides one complex value by another.

static Complex<T> operator /(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The dividend.

right Complex<T>

The divisor.

Returns

Complex<T>

The quotient left divided by right.

Remarks

Division uses Smith's algorithm, which factors out the divisor component of larger magnitude to avoid intermediate overflow, matching Complex bit for bit for finite inputs.

operator ==(Complex<T>, Complex<T>)

Determines whether two complex values are equal, comparing components with floating-point equality.

static bool operator ==(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first value.

right Complex<T>

The second value.

Returns

bool

true if both components are equal under floating-point equality; otherwise, false. A component that is NaN is not equal to itself, and positive and negative zero compare equal.

operator ++(Complex<T>)

Returns the complex value increased by the real unit one.

static Complex<T> operator ++(Complex<T> value)

Parameters

value Complex<T>

The value to increment.

Returns

Complex<T>

The value with 1 added to its real component.

operator !=(Complex<T>, Complex<T>)

Determines whether two complex values are unequal, comparing components with floating-point equality.

static bool operator !=(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first value.

right Complex<T>

The second value.

Returns

bool

true if the values differ under floating-point equality; otherwise, false.

operator *(Complex<T>, Complex<T>)

Multiplies two complex values.

static Complex<T> operator *(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The first factor.

right Complex<T>

The second factor.

Returns

Complex<T>

The product left times right.

Remarks

The product is evaluated with the direct four-multiply form (ac − bd) + (bc + ad)i, matching Complex. No special infinity recovery is applied, so a product of non-finite operands can yield NaN components in the same cases as the framework type.

operator -(Complex<T>, Complex<T>)

Subtracts one complex value from another.

static Complex<T> operator -(Complex<T> left, Complex<T> right)

Parameters

left Complex<T>

The minuend.

right Complex<T>

The subtrahend.

Returns

Complex<T>

The component-wise difference left minus right.

operator -(Complex<T>)

Returns the additive inverse of a complex value.

static Complex<T> operator -(Complex<T> value)

Parameters

value Complex<T>

The value to negate.

Returns

Complex<T>

The value with both components negated.

operator +(Complex<T>)

Returns the complex value unchanged.

static Complex<T> operator +(Complex<T> value)

Parameters

value Complex<T>

The value to return.

Returns

Complex<T>

The unmodified value.

Applies to

ProductVersions
.NET8, 10