Complex<T> Struct
Definition
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
TThe floating-point type used to store the real and imaginary components.
- Implements
-
ISignedNumber<Complex<T>>INumberBase<Complex<T>>IEquatable<Complex<T>>ISpanParsable<Complex<T>>
- 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
realTThe real component.
imaginaryTThe 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
valueComplex<T>The value whose magnitude is computed.
Returns
- T
The Euclidean distance of
valuefrom 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
valueComplex<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
Returns
- Complex<T>
The sum of
leftandright.
Asin(Complex<T>)
Returns the inverse sine (arcsine) of a complex value.
public static Complex<T> Asin(Complex<T> value)
Parameters
valueComplex<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
valueComplex<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
valueComplex<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
valueComplex<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
valueComplex<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
realTThe real component.
imaginaryTThe 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
realTWhen this method returns, contains the real component.
imaginaryTWhen 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
Returns
- Complex<T>
The quotient
leftdivided byright.
Equals(Complex<T>)
Determines whether the specified Complex<T> is equal to this value.
public bool Equals(Complex<T> other)
Parameters
otherComplex<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
objobjectThe object to compare with this value.
Returns
- bool
true if
objis 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
valueComplex<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
magnitudeTThe distance of the value from the origin.
phaseTThe 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
valueComplex<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
valueComplex<T>The value whose logarithm is computed.
baseValueTThe base of the logarithm.
Returns
- Complex<T>
The principal logarithm of
valuein basebaseValue.
Log10(Complex<T>)
Returns the base-10 logarithm of a complex value.
public static Complex<T> Log10(Complex<T> value)
Parameters
valueComplex<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
Returns
- Complex<T>
The product
lefttimesright.
Negate(Complex<T>)
Returns the additive inverse of a complex value.
public static Complex<T> Negate(Complex<T> value)
Parameters
valueComplex<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
sstringThe string to parse.
Returns
- Complex<T>
The complex value the string represents.
Exceptions
- ArgumentNullException
Thrown if
sis null.- FormatException
Thrown if
sis 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
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
valueComplex<T>The base value.
powerTThe 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
valueComplex<T>The value to invert.
Returns
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
valueComplex<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
valueComplex<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
valueComplex<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
Returns
- Complex<T>
The difference
leftminusright.
Tan(Complex<T>)
Returns the tangent of a complex value.
public static Complex<T> Tan(Complex<T> value)
Parameters
valueComplex<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
valueComplex<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
formatstringThe 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
formatstringThe numeric format specifier applied to the real and imaginary components.
formatProviderIFormatProviderThe 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
utf8DestinationSpan<byte>The span that receives the formatted UTF-8 bytes.
bytesWrittenintWhen this method returns, contains the number of bytes written.
formatReadOnlySpan<char>The numeric format specifier applied to each component.
providerIFormatProviderThe culture used to render the numeric components.
Returns
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
destinationSpan<char>The span that receives the formatted characters.
charsWrittenintWhen this method returns, contains the number of characters written.
formatReadOnlySpan<char>The numeric format specifier applied to each component.
providerIFormatProviderThe culture used to render the numeric components.
Returns
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
sstringThe string to parse.
resultComplex<T>When this method returns, contains the parsed value, or zero on failure.
Returns
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
valueTThe 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
valueComplex<T>The complex number to test.
Returns
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
valueComplex<T>The complex number to test.
Returns
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
valueComplex<T>The complex number to test.
Returns
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
utf8TextReadOnlySpan<byte>The UTF-8 encoded text to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
Returns
- Complex<T>
The complex value the text represents.
Exceptions
- FormatException
utf8Textis 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
sReadOnlySpan<char>The span to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
Returns
- Complex<T>
The complex value the span represents.
Exceptions
- FormatException
Thrown if
sis 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
sstringThe string to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
Returns
- Complex<T>
The complex value the string represents.
Exceptions
- ArgumentNullException
Thrown if
sis null.- FormatException
Thrown if
sis 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
valueComplex<T>The value for which to get its absolute.
Returns
- Complex<T>
The absolute of
value.
Exceptions
- OverflowException
The absolute of
valueis 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
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsComplexNumber(Complex<T>)
Determines if a value represents a complex number.
static bool INumberBase<Complex<T>>.IsComplexNumber(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
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
valueComplex<T>The value to be checked.
Returns
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
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsInteger(Complex<T>)
Determines if a value represents an integral number.
static bool INumberBase<Complex<T>>.IsInteger(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
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
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsNegativeInfinity(Complex<T>)
Determines if a value is negative infinity.
static bool INumberBase<Complex<T>>.IsNegativeInfinity(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsNormal(Complex<T>)
Determines if a value is normal.
static bool INumberBase<Complex<T>>.IsNormal(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
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
valueComplex<T>The value to be checked.
Returns
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
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsPositiveInfinity(Complex<T>)
Determines if a value is positive infinity.
static bool INumberBase<Complex<T>>.IsPositiveInfinity(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsRealNumber(Complex<T>)
Determines if a value represents a real number.
static bool INumberBase<Complex<T>>.IsRealNumber(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsSubnormal(Complex<T>)
Determines if a value is subnormal.
static bool INumberBase<Complex<T>>.IsSubnormal(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
INumberBase<Complex<T>>.IsZero(Complex<T>)
Determines if a value is zero.
static bool INumberBase<Complex<T>>.IsZero(Complex<T> value)
Parameters
valueComplex<T>The value to be checked.
Returns
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
Returns
- Complex<T>
xif it has a greater magnitude thany; 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
Returns
- Complex<T>
xif it has a greater magnitude thany; 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
Returns
- Complex<T>
xif it has a lesser magnitude thany; 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
Returns
- Complex<T>
xif it has a lesser magnitude thany; 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
sReadOnlySpan<char>The span of characters to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.
Returns
- Complex<T>
The result of parsing
s.
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.- FormatException
sis not in the correct format.- OverflowException
sis 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
sstringThe string to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.
Returns
- Complex<T>
The result of parsing
s.
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.- ArgumentNullException
sis null.- FormatException
sis not in the correct format.- OverflowException
sis 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
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
valueTOtherThe value that's used to create the instance of Complex<T>.
resultComplex<T>When this method returns, contains an instance of Complex<T> converted from
value.
Returns
Type Parameters
TOtherThe type of
value.
Exceptions
- OverflowException
valueis 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
valueTOtherThe value that is used to create the instance of Complex<T>.
resultComplex<T>When this method returns, contains an instance of Complex<T> converted from
value.
Returns
Type Parameters
TOtherThe 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
valueTOtherThe value that is used to create the instance of Complex<T>.
resultComplex<T>When this method returns, contains an instance of Complex<T> converted from
value.
Returns
Type Parameters
TOtherThe 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
valueComplex<T>The value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould be converted.
Exceptions
- OverflowException
valueis not representable byTOther.
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
valueComplex<T>The value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould 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
valueComplex<T>The value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould 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
sReadOnlySpan<char>The span of characters to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.resultComplex<T>On return, contains the result of succesfully parsing
sor an undefined value on failure.
Returns
Exceptions
- ArgumentException
styleis 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
sstringThe string to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.resultComplex<T>On return, contains the result of succesfully parsing
sor an undefined value on failure.
Returns
Exceptions
- ArgumentException
styleis 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
utf8TextReadOnlySpan<byte>The UTF-8 encoded text to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
resultComplex<T>When this method returns, contains the parsed value, or the default value on failure.
Returns
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
sReadOnlySpan<char>The span to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
resultComplex<T>When this method returns, contains the parsed value, or zero on failure.
Returns
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
sstringThe string to parse.
providerIFormatProviderThe culture used to interpret the numeric components.
resultComplex<T>When this method returns, contains the parsed value, or zero on failure.
Returns
Zero
Gets a Complex<T> representing the value zero.
static Complex<T> Zero { get; }
Returns
- Complex<T>
The complex value
0 + 0i, which is alsodefault(Complex<T>).
operator +(Complex<T>, Complex<T>)
Adds two complex values.
static Complex<T> operator +(Complex<T> left, Complex<T> right)
Parameters
Returns
- Complex<T>
The component-wise sum of
leftandright.
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
valueComplex<T>The value to decrement.
Returns
- Complex<T>
The value with
1subtracted 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
Returns
- Complex<T>
The quotient
leftdivided byright.
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
Returns
operator ++(Complex<T>)
Returns the complex value increased by the real unit one.
static Complex<T> operator ++(Complex<T> value)
Parameters
valueComplex<T>The value to increment.
Returns
- Complex<T>
The value with
1added 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
Returns
operator *(Complex<T>, Complex<T>)
Multiplies two complex values.
static Complex<T> operator *(Complex<T> left, Complex<T> right)
Parameters
Returns
- Complex<T>
The product
lefttimesright.
Remarks
operator -(Complex<T>, Complex<T>)
Subtracts one complex value from another.
static Complex<T> operator -(Complex<T> left, Complex<T> right)
Parameters
Returns
- Complex<T>
The component-wise difference
leftminusright.
operator -(Complex<T>)
Returns the additive inverse of a complex value.
static Complex<T> operator -(Complex<T> value)
Parameters
valueComplex<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
valueComplex<T>The value to return.
Returns
- Complex<T>
The unmodified
value.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |