Skip to content

Commit 8424804

Browse files
Convert Zero/One/ImaginaryOne/NaN/Infinity from static readonly fields to static properties in Complex<T>; remove redundant INumberBase.One/Zero explicit impls
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/4daa6a5a-87a9-46b6-b055-56ce91e228a2 Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
1 parent 0eb1d82 commit 8424804

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,17 @@ namespace System.Numerics
403403
where T : System.Numerics.IFloatingPointIeee754<T>, System.Numerics.IMinMaxValue<T>
404404
{
405405
private readonly int _dummyPrimitive;
406-
public static readonly System.Numerics.Complex<T> ImaginaryOne;
407-
public static readonly System.Numerics.Complex<T> Infinity;
408-
public static readonly System.Numerics.Complex<T> NaN;
409-
public static readonly System.Numerics.Complex<T> One;
410-
public static readonly System.Numerics.Complex<T> Zero;
406+
public static System.Numerics.Complex<T> ImaginaryOne { get { throw null; } }
407+
public static System.Numerics.Complex<T> Infinity { get { throw null; } }
408+
public static System.Numerics.Complex<T> NaN { get { throw null; } }
409+
public static System.Numerics.Complex<T> One { get { throw null; } }
410+
public static System.Numerics.Complex<T> Zero { get { throw null; } }
411411
public Complex(T real, T imaginary) { throw null; }
412412
public T Imaginary { get { throw null; } }
413413
public T Real { get { throw null; } }
414414
static System.Numerics.Complex<T> System.Numerics.IAdditiveIdentity<System.Numerics.Complex<T>,System.Numerics.Complex<T>>.AdditiveIdentity { get { throw null; } }
415415
static System.Numerics.Complex<T> System.Numerics.IMultiplicativeIdentity<System.Numerics.Complex<T>,System.Numerics.Complex<T>>.MultiplicativeIdentity { get { throw null; } }
416-
static System.Numerics.Complex<T> System.Numerics.INumberBase<System.Numerics.Complex<T>>.One { get { throw null; } }
417416
static int System.Numerics.INumberBase<System.Numerics.Complex<T>>.Radix { get { throw null; } }
418-
static System.Numerics.Complex<T> System.Numerics.INumberBase<System.Numerics.Complex<T>>.Zero { get { throw null; } }
419417
static System.Numerics.Complex<T> System.Numerics.ISignedNumber<System.Numerics.Complex<T>>.NegativeOne { get { throw null; } }
420418
public static T Abs(System.Numerics.Complex<T> value) { throw null; }
421419
public static System.Numerics.Complex<T> Acos(System.Numerics.Complex<T> value) { throw null; }

src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.Generic.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public readonly struct Complex<T>
2323
IUtf8SpanFormattable
2424
where T : IFloatingPointIeee754<T>, IMinMaxValue<T>
2525
{
26-
public static readonly Complex<T> Zero = new(T.Zero, T.Zero);
27-
public static readonly Complex<T> One = new(T.One, T.Zero);
28-
public static readonly Complex<T> ImaginaryOne = new(T.Zero, T.One);
29-
public static readonly Complex<T> NaN = new(T.NaN, T.NaN);
30-
public static readonly Complex<T> Infinity = new(T.PositiveInfinity, T.PositiveInfinity);
26+
public static Complex<T> Zero => new(T.Zero, T.Zero);
27+
public static Complex<T> One => new(T.One, T.Zero);
28+
public static Complex<T> ImaginaryOne => new(T.Zero, T.One);
29+
public static Complex<T> NaN => new(T.NaN, T.NaN);
30+
public static Complex<T> Infinity => new(T.PositiveInfinity, T.PositiveInfinity);
3131

3232
// 1 / Log(10)
3333
private static readonly T s_inverseOfLog10 = T.One / T.Log(T.CreateChecked(10));
@@ -715,7 +715,7 @@ public static implicit operator Complex<T>(T value)
715715
//
716716

717717
/// <inheritdoc cref="IAdditiveIdentity{TSelf, TResult}.AdditiveIdentity" />
718-
static Complex<T> IAdditiveIdentity<Complex<T>, Complex<T>>.AdditiveIdentity => new(T.Zero, T.Zero);
718+
static Complex<T> IAdditiveIdentity<Complex<T>, Complex<T>>.AdditiveIdentity => Zero;
719719

720720
//
721721
// IDecrementOperators
@@ -736,21 +736,15 @@ public static implicit operator Complex<T>(T value)
736736
//
737737

738738
/// <inheritdoc cref="IMultiplicativeIdentity{TSelf, TResult}.MultiplicativeIdentity" />
739-
static Complex<T> IMultiplicativeIdentity<Complex<T>, Complex<T>>.MultiplicativeIdentity => new(T.One, T.Zero);
739+
static Complex<T> IMultiplicativeIdentity<Complex<T>, Complex<T>>.MultiplicativeIdentity => One;
740740

741741
//
742742
// INumberBase
743743
//
744744

745-
/// <inheritdoc cref="INumberBase{TSelf}.One" />
746-
static Complex<T> INumberBase<Complex<T>>.One => new(T.One, T.Zero);
747-
748745
/// <inheritdoc cref="INumberBase{TSelf}.Radix" />
749746
static int INumberBase<Complex<T>>.Radix => T.Radix;
750747

751-
/// <inheritdoc cref="INumberBase{TSelf}.Zero" />
752-
static Complex<T> INumberBase<Complex<T>>.Zero => new(T.Zero, T.Zero);
753-
754748
/// <inheritdoc cref="INumberBase{TSelf}.Abs(TSelf)" />
755749
static Complex<T> INumberBase<Complex<T>>.Abs(Complex<T> value) => Abs(value);
756750

0 commit comments

Comments
 (0)