Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace System.Numerics
public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value, out System.Numerics.BigInteger result) { throw null; }
public bool TryWriteBytes(System.Span<byte> destination, out int bytesWritten, bool isUnsigned = false, bool isBigEndian = false) { throw null; }
}
public readonly partial struct Complex : System.IEquatable<System.Numerics.Complex>, System.IFormattable
public readonly partial struct Complex : System.IEquatable<System.Numerics.Complex>, System.IFormattable, System.ISpanFormattable, System.Numerics.IAdditionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IAdditiveIdentity<System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IDecrementOperators<System.Numerics.Complex>, System.Numerics.IDivisionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IEqualityOperators<System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IIncrementOperators<System.Numerics.Complex>, System.Numerics.IMultiplicativeIdentity<System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IMultiplyOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.INumberBase<System.Numerics.Complex>, System.Numerics.ISignedNumber<System.Numerics.Complex>, System.Numerics.ISubtractionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IUnaryNegationOperators<System.Numerics.Complex, System.Numerics.Complex>, System.Numerics.IUnaryPlusOperators<System.Numerics.Complex, System.Numerics.Complex>
{
private readonly int _dummyPrimitive;
public static readonly System.Numerics.Complex ImaginaryOne;
Expand All @@ -178,6 +178,11 @@ namespace System.Numerics
public double Magnitude { get { throw null; } }
public double Phase { get { throw null; } }
public double Real { get { throw null; } }
static System.Numerics.Complex System.Numerics.IAdditiveIdentity<System.Numerics.Complex, System.Numerics.Complex>.AdditiveIdentity { get { throw null; } }
static System.Numerics.Complex System.Numerics.IMultiplicativeIdentity<System.Numerics.Complex, System.Numerics.Complex>.MultiplicativeIdentity { get { throw null; } }
static System.Numerics.Complex System.Numerics.INumberBase<System.Numerics.Complex>.One { get { throw null; } }
static System.Numerics.Complex System.Numerics.INumberBase<System.Numerics.Complex>.Zero { get { throw null; } }
static System.Numerics.Complex System.Numerics.ISignedNumber<System.Numerics.Complex>.NegativeOne { get { throw null; } }
public static double Abs(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Acos(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Add(double left, System.Numerics.Complex right) { throw null; }
Expand Down Expand Up @@ -209,6 +214,7 @@ namespace System.Numerics
public static System.Numerics.Complex operator +(double left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator +(System.Numerics.Complex left, double right) { throw null; }
public static System.Numerics.Complex operator +(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator --(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex operator /(double left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator /(System.Numerics.Complex left, double right) { throw null; }
public static System.Numerics.Complex operator /(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
Expand All @@ -229,6 +235,7 @@ namespace System.Numerics
public static implicit operator System.Numerics.Complex (uint value) { throw null; }
[System.CLSCompliantAttribute(false)]
public static implicit operator System.Numerics.Complex (ulong value) { throw null; }
public static System.Numerics.Complex operator ++(System.Numerics.Complex value) { throw null; }
public static bool operator !=(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator *(double left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator *(System.Numerics.Complex left, double right) { throw null; }
Expand All @@ -237,17 +244,27 @@ namespace System.Numerics
public static System.Numerics.Complex operator -(System.Numerics.Complex left, double right) { throw null; }
public static System.Numerics.Complex operator -(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex operator -(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex operator +(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Pow(System.Numerics.Complex value, double power) { throw null; }
public static System.Numerics.Complex Pow(System.Numerics.Complex value, System.Numerics.Complex power) { throw null; }
public static System.Numerics.Complex Reciprocal(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Sin(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Sinh(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Sqrt(System.Numerics.Complex value) { throw null; }
static System.Numerics.Complex System.Numerics.IAdditionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>.operator checked +(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
static System.Numerics.Complex System.Numerics.IDecrementOperators<System.Numerics.Complex>.operator checked --(System.Numerics.Complex value) { throw null; }
static System.Numerics.Complex System.Numerics.IDivisionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>.operator checked /(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
static System.Numerics.Complex System.Numerics.IIncrementOperators<System.Numerics.Complex>.operator checked ++(System.Numerics.Complex value) { throw null; }
static System.Numerics.Complex System.Numerics.IMultiplyOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>.operator checked *(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
static System.Numerics.Complex System.Numerics.ISubtractionOperators<System.Numerics.Complex, System.Numerics.Complex, System.Numerics.Complex>.operator checked -(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
static System.Numerics.Complex System.Numerics.IUnaryNegationOperators<System.Numerics.Complex, System.Numerics.Complex>.operator checked -(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Subtract(double left, System.Numerics.Complex right) { throw null; }
public static System.Numerics.Complex Subtract(System.Numerics.Complex left, double right) { throw null; }
public static System.Numerics.Complex Subtract(System.Numerics.Complex left, System.Numerics.Complex right) { throw null; }
public bool TryFormat(System.Span<char> destination, out int charsWritten, System.ReadOnlySpan<char> format, System.IFormatProvider? provider) { throw null; }
public static System.Numerics.Complex Tan(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Tanh(System.Numerics.Complex value) { throw null; }

public override string ToString() { throw null; }
public string ToString(System.IFormatProvider? provider) { throw null; }
public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format) { throw null; }
Expand Down
147 changes: 146 additions & 1 deletion src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace System.Numerics
Expand All @@ -13,7 +14,11 @@ namespace System.Numerics
/// </summary>
[Serializable]
[TypeForwardedFrom("System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Complex : IEquatable<Complex>, IFormattable
public readonly struct Complex
: IEquatable<Complex>,
IFormattable,
INumberBase<Complex>,
ISignedNumber<Complex>
{
public static readonly Complex Zero = new Complex(0.0, 0.0);
public static readonly Complex One = new Complex(1.0, 0.0);
Expand Down Expand Up @@ -849,5 +854,145 @@ public static explicit operator Complex(decimal value)
{
return new Complex((double)value, 0.0);
}

//
// IAdditionOperators
//

/// <inheritdoc cref="IAdditionOperators{TSelf, TOther, TResult}.op_Addition(TSelf, TOther)" />
static Complex IAdditionOperators<Complex, Complex, Complex>.operator checked +(Complex left, Complex right) => left + right;

//
// IAdditiveIdentity
//

/// <inheritdoc cref="IAdditiveIdentity{TSelf, TResult}.AdditiveIdentity" />
static Complex IAdditiveIdentity<Complex, Complex>.AdditiveIdentity => new Complex(0.0, 0.0);

//
// IDecrementOperators
//

/// <inheritdoc cref="IDecrementOperators{TSelf}.op_Decrement(TSelf)" />
public static Complex operator --(Complex value) => value - One;

/// <inheritdoc cref="IDecrementOperators{TSelf}.op_Decrement(TSelf)" />
static Complex IDecrementOperators<Complex>.operator checked --(Complex value) => --value;

//
// IDivisionOperators
//

/// <inheritdoc cref="IDivisionOperators{TSelf, TOther, TResult}.op_CheckedDivision(TSelf, TOther)" />
static Complex IDivisionOperators<Complex, Complex, Complex>.operator checked /(Complex left, Complex right) => left / right;

//
// IIncrementOperators
//

/// <inheritdoc cref="IIncrementOperators{TSelf}.op_Increment(TSelf)" />
public static Complex operator ++(Complex value) => value + One;

/// <inheritdoc cref="IIncrementOperators{TSelf}.op_CheckedIncrement(TSelf)" />
static Complex IIncrementOperators<Complex>.operator checked ++(Complex value) => ++value;

//
// IMultiplicativeIdentity
//

/// <inheritdoc cref="IMultiplicativeIdentity{TSelf, TResult}.MultiplicativeIdentity" />
static Complex IMultiplicativeIdentity<Complex, Complex>.MultiplicativeIdentity => new Complex(1.0, 0.0);

//
// IMultiplyOperators
//

/// <inheritdoc cref="IMultiplyOperators{TSelf, TOther, TResult}.op_CheckedMultiply(TSelf, TOther)" />
static Complex IMultiplyOperators<Complex, Complex, Complex>.operator checked *(Complex left, Complex right) => left * right;

//
// INumberBase
//

/// <inheritdoc cref="INumberBase{TSelf}.One" />
static Complex INumberBase<Complex>.One => new Complex(1.0, 0.0);

/// <inheritdoc cref="INumberBase{TSelf}.Zero" />
static Complex INumberBase<Complex>.Zero => new Complex(0.0, 0.0);

//
// ISignedNumber
//

/// <inheritdoc cref="ISignedNumber{TSelf}.NegativeOne" />
static Complex ISignedNumber<Complex>.NegativeOne => new Complex(-1.0, 0.0);

//
// ISpanFormattable
//

/// <inheritdoc cref="ISpanFormattable.TryFormat(Span{char}, out int, ReadOnlySpan{char}, IFormatProvider?)" />
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
int charsWrittenSoFar = 0;

// We have at least 6 more characters for: (0, 0)
if (destination.Length < 6)
{
charsWritten = charsWrittenSoFar;
return false;
}

destination[charsWrittenSoFar++] = '(';

bool tryFormatSucceeded = m_real.TryFormat(destination.Slice(charsWrittenSoFar), out int tryFormatCharsWritten, format, provider);
charsWrittenSoFar += tryFormatCharsWritten;

// We have at least 4 more characters for: , 0)
if (!tryFormatSucceeded || (destination.Length < (charsWrittenSoFar + 4)))
{
charsWritten = charsWrittenSoFar;
return false;
}

destination[charsWrittenSoFar++] = ',';
destination[charsWrittenSoFar++] = ' ';

tryFormatSucceeded = m_imaginary.TryFormat(destination.Slice(charsWrittenSoFar), out tryFormatCharsWritten, format, provider);
charsWrittenSoFar += tryFormatCharsWritten;

// We have at least 1 more character for: )
if (!tryFormatSucceeded || (destination.Length < (charsWrittenSoFar + 1)))
{
charsWritten = charsWrittenSoFar;
return false;
}

destination[charsWrittenSoFar++] = ')';

charsWritten = charsWrittenSoFar;
return true;
}

//
// ISubtractionOperators
//

/// <inheritdoc cref="ISubtractionOperators{TSelf, TOther, TResult}.op_CheckedSubtraction(TSelf, TOther)" />
static Complex ISubtractionOperators<Complex, Complex, Complex>.operator checked -(Complex left, Complex right) => left - right;

//
// IUnaryNegationOperators
//

/// <inheritdoc cref="IUnaryNegationOperators{TSelf, TResult}.op_CheckedUnaryNegation(TSelf)" />
static Complex IUnaryNegationOperators<Complex, Complex>.operator checked -(Complex value) => -value;

//
// IUnaryPlusOperators
//

/// <inheritdoc cref="IUnaryPlusOperators{TSelf, TResult}.op_UnaryPlus(TSelf)" />
public static Complex operator +(Complex value) => value;
}
}
Loading