Skip to content

Commit 4af1fa8

Browse files
committed
WIP: add AllBitsSet to BigInteger with the wrong DIM, add test case.
1 parent 5877e8b commit 4af1fa8

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

src/libraries/Common/tests/System/GenericMathHelpers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public static class BinaryIntegerHelper<TSelf>
5959
public static class BinaryNumberHelper<TSelf>
6060
where TSelf : IBinaryNumber<TSelf>
6161
{
62+
public static TSelf AllBitsSet => TSelf.AllBitsSet;
63+
6264
public static bool IsPow2(TSelf value) => TSelf.IsPow2(value);
6365

6466
public static TSelf Log2(TSelf value) => TSelf.Log2(value);

src/libraries/System.Private.CoreLib/src/System/Numerics/IBinaryNumber.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public interface IBinaryNumber<TSelf>
1010
INumber<TSelf>
1111
where TSelf : IBinaryNumber<TSelf>
1212
{
13+
/// <summary>Gets an instance of the binary type in which all bits are set.</summary>
14+
static virtual TSelf AllBitsSet => TSelf.One; // TODO: add the correct DIM when I am confident everything works
15+
1316
/// <summary>Determines if a value is a power of two.</summary>
1417
/// <param name="value">The value to be checked.</param>
1518
/// <returns><c>true</c> if <paramref name="value" /> is a power of two; otherwise, <c>false</c>.</returns>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace System.Numerics
6060
public static bool IsNegative(System.Numerics.BigInteger value) { throw null; }
6161
public static bool IsOddInteger(System.Numerics.BigInteger value) { throw null; }
6262
public static bool IsPositive(System.Numerics.BigInteger value) { throw null; }
63+
static BigInteger System.Numerics.IBinaryNumber<BigInteger>.AllBitsSet { get { throw null; } }
6364
public static bool IsPow2(System.Numerics.BigInteger value) { throw null; }
6465
public static System.Numerics.BigInteger LeadingZeroCount(System.Numerics.BigInteger value) { throw null; }
6566
public static double Log(System.Numerics.BigInteger value) { throw null; }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,6 +3821,9 @@ private int GetGenericMathByteCount()
38213821
// IBinaryNumber
38223822
//
38233823

3824+
/// <inheritdoc cref="IBinaryNumber{TSelf}.AllBitsSet" />
3825+
static BigInteger IBinaryNumber<BigInteger>.AllBitsSet => MinusOne;
3826+
38243827
/// <inheritdoc cref="IBinaryNumber{TSelf}.IsPow2(TSelf)" />
38253828
public static bool IsPow2(BigInteger value) => value.IsPowerOfTwo;
38263829

src/libraries/System.Runtime.Numerics/tests/BigIntegerTests.GenericMath.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ public static void TryWriteLittleEndianTest()
550550
// IBinaryNumber
551551
//
552552

553+
[Fact]
554+
public static void AllBitsSetTest()
555+
{
556+
Assert.Equal(NegativeOne, BinaryNumberHelper<BigInteger>.AllBitsSet);
557+
}
558+
553559
[Fact]
554560
public static void IsPow2Test()
555561
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10382,6 +10382,7 @@ public partial interface IBinaryInteger<TSelf> : System.IComparable, System.ICom
1038210382
}
1038310383
public partial interface IBinaryNumber<TSelf> : System.IComparable, System.IComparable<TSelf>, System.IEquatable<TSelf>, System.IFormattable, System.IParsable<TSelf>, System.ISpanFormattable, System.ISpanParsable<TSelf>, System.Numerics.IAdditionOperators<TSelf, TSelf, TSelf>, System.Numerics.IAdditiveIdentity<TSelf, TSelf>, System.Numerics.IBitwiseOperators<TSelf, TSelf, TSelf>, System.Numerics.IComparisonOperators<TSelf, TSelf>, System.Numerics.IDecrementOperators<TSelf>, System.Numerics.IDivisionOperators<TSelf, TSelf, TSelf>, System.Numerics.IEqualityOperators<TSelf, TSelf>, System.Numerics.IIncrementOperators<TSelf>, System.Numerics.IModulusOperators<TSelf, TSelf, TSelf>, System.Numerics.IMultiplicativeIdentity<TSelf, TSelf>, System.Numerics.IMultiplyOperators<TSelf, TSelf, TSelf>, System.Numerics.INumber<TSelf>, System.Numerics.INumberBase<TSelf>, System.Numerics.ISubtractionOperators<TSelf, TSelf, TSelf>, System.Numerics.IUnaryNegationOperators<TSelf, TSelf>, System.Numerics.IUnaryPlusOperators<TSelf, TSelf> where TSelf : System.Numerics.IBinaryNumber<TSelf>
1038410384
{
10385+
static virtual TSelf AllBitsSet => throw null;
1038510386
static abstract bool IsPow2(TSelf value);
1038610387
static abstract TSelf Log2(TSelf value);
1038710388
}

0 commit comments

Comments
 (0)