Skip to content

Commit

Permalink
Adding more tests for the generic math feature (#55377)
Browse files Browse the repository at this point in the history
* Fixing some issues in the generic math implementation

* Adding generic math tests for integer types
  • Loading branch information
tannergooding authored Jul 11, 2021
1 parent 6a47ecf commit bb39822
Show file tree
Hide file tree
Showing 32 changed files with 14,313 additions and 255 deletions.
12 changes: 6 additions & 6 deletions src/libraries/System.Private.CoreLib/src/System/Byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ static byte IBinaryInteger<byte>.PopCount(byte value)
=> (byte)BitOperations.PopCount(value);

[RequiresPreviewFeatures]
static byte IBinaryInteger<byte>.RotateLeft(byte value, byte rotateAmount)
static byte IBinaryInteger<byte>.RotateLeft(byte value, int rotateAmount)
=> (byte)((value << (rotateAmount & 7)) | (value >> ((8 - rotateAmount) & 7)));

[RequiresPreviewFeatures]
static byte IBinaryInteger<byte>.RotateRight(byte value, byte rotateAmount)
static byte IBinaryInteger<byte>.RotateRight(byte value, int rotateAmount)
=> (byte)((value >> (rotateAmount & 7)) | (value << ((8 - rotateAmount) & 7)));

[RequiresPreviewFeatures]
Expand Down Expand Up @@ -382,11 +382,11 @@ static byte IBinaryNumber<byte>.Log2(byte value)

[RequiresPreviewFeatures]
static byte IDecrementOperators<byte>.operator --(byte value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked byte IDecrementOperators<byte>.operator --(byte value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -418,11 +418,11 @@ static byte IBinaryNumber<byte>.Log2(byte value)

[RequiresPreviewFeatures]
static byte IIncrementOperators<byte>.operator ++(byte value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked byte IIncrementOperators<byte>.operator ++(byte value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
12 changes: 6 additions & 6 deletions src/libraries/System.Private.CoreLib/src/System/Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,11 +1093,11 @@ static char IBinaryInteger<char>.PopCount(char value)
=> (char)BitOperations.PopCount(value);

[RequiresPreviewFeatures]
static char IBinaryInteger<char>.RotateLeft(char value, char rotateAmount)
static char IBinaryInteger<char>.RotateLeft(char value, int rotateAmount)
=> (char)((value << (rotateAmount & 15)) | (value >> ((16 - rotateAmount) & 15)));

[RequiresPreviewFeatures]
static char IBinaryInteger<char>.RotateRight(char value, char rotateAmount)
static char IBinaryInteger<char>.RotateRight(char value, int rotateAmount)
=> (char)((value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15)));

[RequiresPreviewFeatures]
Expand Down Expand Up @@ -1162,11 +1162,11 @@ static char IBinaryNumber<char>.Log2(char value)

[RequiresPreviewFeatures]
static char IDecrementOperators<char>.operator --(char value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked char IDecrementOperators<char>.operator --(char value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -1198,11 +1198,11 @@ static char IBinaryNumber<char>.Log2(char value)

[RequiresPreviewFeatures]
static char IIncrementOperators<char>.operator ++(char value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked char IIncrementOperators<char>.operator ++(char value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,11 @@ object IConvertible.ToType(Type type, IFormatProvider? provider)

[RequiresPreviewFeatures]
static decimal IDecrementOperators<decimal>.operator --(decimal value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked decimal IDecrementOperators<decimal>.operator --(decimal value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -1162,11 +1162,11 @@ object IConvertible.ToType(Type type, IFormatProvider? provider)

[RequiresPreviewFeatures]
static decimal IIncrementOperators<decimal>.operator ++(decimal value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked decimal IIncrementOperators<decimal>.operator ++(decimal value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ static double IBinaryNumber<double>.Log2(double value)

[RequiresPreviewFeatures]
static double IDecrementOperators<double>.operator --(double value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked double IDecrementOperators<double>.operator --(double value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -828,11 +828,11 @@ static double IFloatingPoint<double>.Truncate(double x)

[RequiresPreviewFeatures]
static double IIncrementOperators<double>.operator ++(double value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked double IIncrementOperators<double>.operator ++(double value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,15 @@ static Half IBinaryNumber<Half>.Log2(Half value)
static Half IDecrementOperators<Half>.operator --(Half value)
{
var tmp = (float)value;
tmp--;
--tmp;
return (Half)tmp;
}

// [RequiresPreviewFeatures]
// static checked Half IDecrementOperators<Half>.operator --(Half value)
// {
// var tmp = (float)value;
// tmp--;
// --tmp;
// return (Half)tmp;
// }

Expand Down Expand Up @@ -1132,15 +1132,15 @@ static Half IFloatingPoint<Half>.Truncate(Half x)
static Half IIncrementOperators<Half>.operator ++(Half value)
{
var tmp = (float)value;
tmp++;
++tmp;
return (Half)tmp;
}

// [RequiresPreviewFeatures]
// static checked Half IIncrementOperators<Half>.operator ++(Half value)
// {
// var tmp = (float)value;
// tmp++;
// ++tmp;
// return (Half)tmp;
// }

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/IInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public interface IBinaryInteger<TSelf>
/// <param name="value">The value which is rotated left by <paramref name="rotateAmount" />.</param>
/// <param name="rotateAmount">The amount by which <paramref name="value" /> is rotated left.</param>
/// <returns>The result of rotating <paramref name="value" /> left by <paramref name="rotateAmount" />.</returns>
static abstract TSelf RotateLeft(TSelf value, TSelf rotateAmount);
static abstract TSelf RotateLeft(TSelf value, int rotateAmount);

/// <summary>Rotates a value right by a given amount.</summary>
/// <param name="value">The value which is rotated right by <paramref name="rotateAmount" />.</param>
/// <param name="rotateAmount">The amount by which <paramref name="value" /> is rotated right.</param>
/// <returns>The result of rotating <paramref name="value" /> right by <paramref name="rotateAmount" />.</returns>
static abstract TSelf RotateRight(TSelf value, TSelf rotateAmount);
static abstract TSelf RotateRight(TSelf value, int rotateAmount);

/// <summary>Computes the number of trailing zeros in a value.</summary>
/// <param name="value">The value whose trailing zeroes are to be counted.</param>
Expand Down
18 changes: 9 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/Int16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ static short IBinaryInteger<short>.PopCount(short value)
=> (short)BitOperations.PopCount((ushort)value);

[RequiresPreviewFeatures]
static short IBinaryInteger<short>.RotateLeft(short value, short rotateAmount)
=> (short)((value << (rotateAmount & 15)) | (value >> ((16 - rotateAmount) & 15)));
static short IBinaryInteger<short>.RotateLeft(short value, int rotateAmount)
=> (short)((value << (rotateAmount & 15)) | ((ushort)value >> ((16 - rotateAmount) & 15)));

[RequiresPreviewFeatures]
static short IBinaryInteger<short>.RotateRight(short value, short rotateAmount)
=> (short)((value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15)));
static short IBinaryInteger<short>.RotateRight(short value, int rotateAmount)
=> (short)(((ushort)value >> (rotateAmount & 15)) | (value << ((16 - rotateAmount) & 15)));

[RequiresPreviewFeatures]
static short IBinaryInteger<short>.TrailingZeroCount(short value)
Expand Down Expand Up @@ -391,11 +391,11 @@ static short IBinaryNumber<short>.Log2(short value)

[RequiresPreviewFeatures]
static short IDecrementOperators<short>.operator --(short value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked short IDecrementOperators<short>.operator --(short value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -427,11 +427,11 @@ static short IBinaryNumber<short>.Log2(short value)

[RequiresPreviewFeatures]
static short IIncrementOperators<short>.operator ++(short value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked short IIncrementOperators<short>.operator ++(short value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down Expand Up @@ -565,7 +565,7 @@ static short INumber<short>.CreateSaturating<TOther>(TOther value)
{
if (typeof(TOther) == typeof(byte))
{
return (short)(object)value;
return (byte)(object)value;
}
else if (typeof(TOther) == typeof(char))
{
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Int32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,11 @@ static int IBinaryNumber<int>.Log2(int value)

[RequiresPreviewFeatures]
static int IDecrementOperators<int>.operator --(int value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked int IDecrementOperators<int>.operator --(int value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -419,11 +419,11 @@ static int IBinaryNumber<int>.Log2(int value)

[RequiresPreviewFeatures]
static int IIncrementOperators<int>.operator ++(int value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked int IIncrementOperators<int>.operator ++(int value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/Int64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ static long IBinaryInteger<long>.PopCount(long value)
=> BitOperations.PopCount((ulong)value);

[RequiresPreviewFeatures]
static long IBinaryInteger<long>.RotateLeft(long value, long rotateAmount)
=> (long)BitOperations.RotateLeft((ulong)value, (int)rotateAmount);
static long IBinaryInteger<long>.RotateLeft(long value, int rotateAmount)
=> (long)BitOperations.RotateLeft((ulong)value, rotateAmount);

[RequiresPreviewFeatures]
static long IBinaryInteger<long>.RotateRight(long value, long rotateAmount)
=> (long)BitOperations.RotateRight((ulong)value, (int)rotateAmount);
static long IBinaryInteger<long>.RotateRight(long value, int rotateAmount)
=> (long)BitOperations.RotateRight((ulong)value, rotateAmount);

[RequiresPreviewFeatures]
static long IBinaryInteger<long>.TrailingZeroCount(long value)
Expand Down Expand Up @@ -370,11 +370,11 @@ static long IBinaryNumber<long>.Log2(long value)

[RequiresPreviewFeatures]
static long IDecrementOperators<long>.operator --(long value)
=> value--;
=> --value;

// [RequiresPreviewFeatures]
// static checked long IDecrementOperators<long>.operator --(long value)
// => checked(value--);
// => checked(--value);

//
// IDivisionOperators
Expand Down Expand Up @@ -406,11 +406,11 @@ static long IBinaryNumber<long>.Log2(long value)

[RequiresPreviewFeatures]
static long IIncrementOperators<long>.operator ++(long value)
=> value++;
=> ++value;

// [RequiresPreviewFeatures]
// static checked long IIncrementOperators<long>.operator ++(long value)
// => checked(value++);
// => checked(++value);

//
// IMinMaxValue
Expand Down
Loading

0 comments on commit bb39822

Please sign in to comment.