diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 4b8f4f3..8558da2 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -23,7 +23,6 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.0.x 8.0.x - name: Add NuGet source @@ -35,9 +34,6 @@ jobs: - name: Build run: dotnet build --no-restore --configuration Release - - name: Test .NET 6 - run: dotnet test --no-build --verbosity normal --configuration Release --framework net6.0 --collect:"XPlat Code Coverage" --results-directory test-results/net6.0 - - name: Test .NET 8 run: dotnet test --no-build --verbosity normal --configuration Release --framework net8.0 --collect:"XPlat Code Coverage" --results-directory test-results/net8.0 diff --git a/X10D.Hosting/X10D.Hosting.csproj b/X10D.Hosting/X10D.Hosting.csproj index cc93b63..74d07d3 100644 --- a/X10D.Hosting/X10D.Hosting.csproj +++ b/X10D.Hosting/X10D.Hosting.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 diff --git a/X10D.Tests/X10D.Tests.csproj b/X10D.Tests/X10D.Tests.csproj index 9ac986d..74bdbc1 100644 --- a/X10D.Tests/X10D.Tests.csproj +++ b/X10D.Tests/X10D.Tests.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 false true xml,cobertura diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index 592e773..3961f95 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 diff --git a/X10D/src/Collections/BinaryIntegerExtensions.cs b/X10D/src/Collections/BinaryIntegerExtensions.cs index 0aec0d0..5edba34 100644 --- a/X10D/src/Collections/BinaryIntegerExtensions.cs +++ b/X10D/src/Collections/BinaryIntegerExtensions.cs @@ -1,4 +1,3 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Numerics; @@ -95,4 +94,3 @@ public static class BinaryIntegerExtensions } } } -#endif diff --git a/X10D/src/Collections/ByteExtensions.cs b/X10D/src/Collections/ByteExtensions.cs index bdcdcce..5498209 100644 --- a/X10D/src/Collections/ByteExtensions.cs +++ b/X10D/src/Collections/ByteExtensions.cs @@ -1,7 +1,3 @@ -#if !NET7_0_OR_GREATER -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -#endif using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -16,46 +12,6 @@ public static class ByteExtensions { private const int Size = sizeof(byte) * 8; -#if !NET7_0_OR_GREATER - /// - /// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 8. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this byte value) - { - var buffer = new bool[Size]; - value.Unpack(buffer); - return buffer; - } - - /// - /// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this byte value, Span destination) - { - if (destination.Length < Size) - { - throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination)); - } - - if (Sse3.IsSupported) - { - UnpackInternal_Ssse3(value, destination); - return; - } - - UnpackInternal_Fallback(value, destination); - } -#endif - [MethodImpl(CompilerResources.MaxOptimization)] internal static void UnpackInternal_Fallback(this byte value, Span destination) { diff --git a/X10D/src/Collections/Int16Extensions.cs b/X10D/src/Collections/Int16Extensions.cs index e3e5570..b744413 100644 --- a/X10D/src/Collections/Int16Extensions.cs +++ b/X10D/src/Collections/Int16Extensions.cs @@ -1,7 +1,3 @@ -#if !NET7_0_OR_GREATER -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -#endif using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -16,46 +12,6 @@ public static class Int16Extensions { private const int Size = sizeof(short) * 8; -#if !NET7_0_OR_GREATER - /// - /// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 16. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this short value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this short value, Span destination) - { - if (destination.Length < Size) - { - throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination)); - } - - if (Sse3.IsSupported) - { - UnpackInternal_Ssse3(value, destination); - return; - } - - UnpackInternal_Fallback(value, destination); - } -#endif - [MethodImpl(CompilerResources.MaxOptimization)] internal static void UnpackInternal_Fallback(this short value, Span destination) { diff --git a/X10D/src/Collections/Int32Extensions.cs b/X10D/src/Collections/Int32Extensions.cs index b74a311..1386541 100644 --- a/X10D/src/Collections/Int32Extensions.cs +++ b/X10D/src/Collections/Int32Extensions.cs @@ -1,7 +1,3 @@ -#if !NET7_0_OR_GREATER -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -#endif using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -16,52 +12,6 @@ public static class Int32Extensions { private const int Size = sizeof(int) * 8; -#if !NET7_0_OR_GREATER - /// - /// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 32. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this int value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this int value, Span destination) - { - if (destination.Length < Size) - { - throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination)); - } - - if (Avx2.IsSupported) - { - UnpackInternal_Avx2(value, destination); - return; - } - - if (Sse3.IsSupported) - { - UnpackInternal_Ssse3(value, destination); - return; - } - - UnpackInternal_Fallback(value, destination); - } -#endif - [MethodImpl(CompilerResources.MaxOptimization)] internal static void UnpackInternal_Fallback(this int value, Span destination) { diff --git a/X10D/src/Collections/Int64Extensions.cs b/X10D/src/Collections/Int64Extensions.cs deleted file mode 100644 index c72dfbd..0000000 --- a/X10D/src/Collections/Int64Extensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -#if !NET7_0_OR_GREATER -using System.Diagnostics.Contracts; - -namespace X10D.Collections; - -/// -/// Collection-related extension methods for . -/// -public static class Int64Extensions -{ - private const int Size = sizeof(long) * 8; - - /// - /// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 64. - [Pure] - public static bool[] Unpack(this long value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - public static void Unpack(this long value, Span destination) - { - if (destination.Length < Size) - { - throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination)); - } - - for (var index = 0; index < Size; index++) - { - destination[index] = (value & (1L << index)) != 0; - } - } -} -#endif diff --git a/X10D/src/Core/IntrinsicExtensions.cs b/X10D/src/Core/IntrinsicExtensions.cs index 7a98d64..1e2fc9d 100644 --- a/X10D/src/Core/IntrinsicExtensions.cs +++ b/X10D/src/Core/IntrinsicExtensions.cs @@ -37,12 +37,7 @@ public static class IntrinsicExtensions for (var i = 0; i < Vector64.Count; i++) { ref byte writeElement = ref Unsafe.Add(ref Unsafe.As, byte>(ref output), i); -#if NET7_0_OR_GREATER writeElement = vector[i] == 0 ? (byte)0 : (byte)1; -#else - byte element = Unsafe.Add(ref Unsafe.As, byte>(ref vector), i); - writeElement = element == 0 ? (byte)0 : (byte)1; -#endif } return output; diff --git a/X10D/src/Core/SpanExtensions.cs b/X10D/src/Core/SpanExtensions.cs index ab79a16..beb4c92 100644 --- a/X10D/src/Core/SpanExtensions.cs +++ b/X10D/src/Core/SpanExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; @@ -6,10 +7,6 @@ using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; using X10D.CompilerServices; -#if NET7_0_OR_GREATER -using System.Diagnostics; -#endif - namespace X10D.Core; /// @@ -93,11 +90,7 @@ public static class SpanExtensions // dotcover disable default: -#if NET7_0_OR_GREATER throw new UnreachableException(string.Format(ExceptionMessages.EnumSizeIsUnexpected, Unsafe.SizeOf())); -#else - throw new ArgumentException(string.Format(ExceptionMessages.EnumSizeIsUnexpected, Unsafe.SizeOf())); -#endif // dotcover enable } } diff --git a/X10D/src/Math/BigIntegerExtensions.cs b/X10D/src/Math/BigIntegerExtensions.cs index 79c936c..da72697 100644 --- a/X10D/src/Math/BigIntegerExtensions.cs +++ b/X10D/src/Math/BigIntegerExtensions.cs @@ -10,41 +10,6 @@ namespace X10D.Math; /// public static class BigIntegerExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this BigInteger value) - { - if (value == 0) - { - return 1; - } - - return (int)(1 + BigInteger.Log10(BigInteger.Abs(value))); - } - - /// - /// Computes the digital root of this 8-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int DigitalRoot(this BigInteger value) - { - BigInteger root = BigInteger.Abs(value).Mod(9); - return (int)(root == 0 ? 9 : root); - } -#endif - /// /// Returns the factorial of the current 64-bit signed integer. /// @@ -172,30 +137,6 @@ public static class BigIntegerExtensions return value * other / value.GreatestCommonFactor(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead - /// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static BigInteger Mod(this BigInteger dividend, BigInteger divisor) - { - BigInteger r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index ce10a7e..2d09419 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -1,4 +1,3 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.Contracts; using System.Numerics; using System.Runtime.CompilerServices; @@ -98,4 +97,3 @@ public static class BinaryIntegerExtensions return value; } } -#endif diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 0bd8486..5f6d77a 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -9,107 +9,6 @@ namespace X10D.Math; /// public static class ByteExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 8-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this byte value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of this 8-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte DigitalRoot(this byte value) - { - int root = value % 9; - return (byte)(root == 0 ? 9 : root); - } - - /// - /// Returns the factorial of the current 8-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this byte value) - { - if (value == 0) - { - return 1; - } - - var result = 1L; - for (byte i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 8-bit unsigned integer, and another 8-bit unsigned integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte GreatestCommonFactor(this byte value, byte other) - { - return (byte)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this byte value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this byte value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 318a948..a331a46 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -9,112 +9,6 @@ namespace X10D.Math; /// public static class Int16Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 16-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this short value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 16-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short DigitalRoot(this short value) - { - short root = System.Math.Abs(value).Mod(9); - return root < 1 ? (short)(9 - root) : root; - } - - /// - /// Returns the factorial of the current 16-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this short value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (short i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 16-bit signed integer, and another 16-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short GreatestCommonFactor(this short value, short other) - { - return (short)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this short value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this short value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -142,30 +36,6 @@ public static class Int16Extensions return (short)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead - /// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short Mod(this short dividend, short divisor) - { - int r = dividend % divisor; - return (short)(r < 0 ? r + divisor : r); - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index e0b05cc..c9eb23f 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -9,112 +9,6 @@ namespace X10D.Math; /// public static class Int32Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 32-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this int value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 32-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int DigitalRoot(this int value) - { - int root = System.Math.Abs(value).Mod(9); - return root < 1 ? 9 - root : root; - } - - /// - /// Returns the factorial of the current 32-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this int value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (var i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 32-bit signed integer, and another 32-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int GreatestCommonFactor(this int value, int other) - { - return (int)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this int value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this int value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -142,30 +36,6 @@ public static class Int32Extensions return (int)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead - /// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Mod(this int dividend, int divisor) - { - int r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index b0c1e58..d000cbe 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -9,117 +9,6 @@ namespace X10D.Math; /// public static class Int64Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 64-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this long value) - { - if (value == 0) - { - return 1; - } - - return 1 + (int)System.Math.Floor(System.Math.Log10(System.Math.Abs(value))); - } - - /// - /// Computes the digital root of this 64-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long DigitalRoot(this long value) - { - long root = System.Math.Abs(value).Mod(9L); - return root < 1L ? 9L - root : root; - } - - /// - /// Returns the factorial of the current 64-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this long value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (var i = 1L; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 64-bit signed integer, and another 64-bit unsigned integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long GreatestCommonFactor(this long value, long other) - { - while (other != 0) - { - (value, other) = (other, value % other); - } - - return value; - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this long value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this long value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -181,30 +70,6 @@ public static class Int64Extensions return value * other / value.GreatestCommonFactor(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead - /// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Mod(this long dividend, long divisor) - { - long r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/MathUtility.cs b/X10D/src/Math/MathUtility.cs index 0ca9365..bcdbb4d 100644 --- a/X10D/src/Math/MathUtility.cs +++ b/X10D/src/Math/MathUtility.cs @@ -127,158 +127,6 @@ public static class MathUtility return (alpha - start) / (end - start); } -#if !NET7_0_OR_GREATER - /// - /// Applies a simple bias function to value. - /// - /// The value to which the bias function will be applied. - /// The bias value. Valid values range from 0-1. - /// The biased result. - /// - /// If is less than 0.5, will be shifted downward; otherwise, upward. - /// - public static float Bias(float value, float bias) - { - return value / ((1.0f / bias - 2.0f) * (1.0f - value) + 1.0f); - } - - /// - /// Applies a simple bias function to value. - /// - /// The value to which the bias function will be applied. - /// The bias value. Valid values range from 0-1. - /// The biased result. - /// - /// If is less than 0.5, will be shifted downward; otherwise, upward. - /// - public static double Bias(double value, double bias) - { - return value / ((1.0 / bias - 2.0) * (1.0 - value) + 1.0); - } - - /// - /// Linearly interpolates from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// - /// The interpolation result as determined by (1 - alpha) * value + alpha * target. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float Lerp(float value, float target, float alpha) - { - // rookie mistake: a + t * (b - a) - // "precise" method: (1 - t) * a + t * b - return ((1.0f - alpha) * value) + (alpha * target); - } - - /// - /// Linearly interpolates from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// - /// The interpolation result as determined by (1 - alpha) * value + alpha * target. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double Lerp(double value, double target, double alpha) - { - // rookie mistake: a + t * (b - a) - // "precise" method: (1 - t) * a + t * b - return ((1.0 - alpha) * value) + (alpha * target); - } - - /// - /// Performs smooth Hermite interpolation from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// The interpolation result. - public static float SmoothStep(float value, float target, float alpha) - { - alpha = System.Math.Clamp(alpha, 0.0f, 1.0f); - alpha = -2.0f * alpha * alpha * alpha + 3.0f * alpha * alpha; - return target * alpha + value * (1.0f - alpha); - } - - /// - /// Performs smooth Hermite interpolation from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// The interpolation result. - public static double SmoothStep(double value, double target, double alpha) - { - alpha = System.Math.Clamp(alpha, 0.0, 1.0); - alpha = -2.0 * alpha * alpha * alpha + 3.0 * alpha * alpha; - return target * alpha + value * (1.0 - alpha); - } - - /// - /// Converts a value from being a percentage of one range, to being the same percentage in a new range. - /// - /// The value to convert. - /// The old minimum value. - /// The old maximum value. - /// The new minimum value. - /// The new maximum value. - /// The scaled value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax) - { - float oldRange = oldMax - oldMin; - float newRange = newMax - newMin; - float alpha = (value - oldMin) / oldRange; - return (alpha * newRange) + newMin; - } - - /// - /// Converts a value from being a percentage of one range, to being the same percentage in a new range. - /// - /// The value to convert. - /// The old minimum value. - /// The old maximum value. - /// The new minimum value. - /// The new maximum value. - /// The scaled value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax) - { - double oldRange = oldMax - oldMin; - double newRange = newMax - newMin; - double alpha = (value - oldMin) / oldRange; - return (alpha * newRange) + newMin; - } - - /// - /// Returns the incremental sawtooth wave of a given value. - /// - /// The value to calculate. - /// The sawtooth wave of the given value. - public static float Sawtooth(float value) - { - return (value - MathF.Floor(value)); - } - - /// - /// Returns the incremental sawtooth wave of a given value. - /// - /// The value to calculate. - /// The sawtooth wave of the given value. - public static double Sawtooth(double value) - { - return (value - System.Math.Floor(value)); - } -#endif - /// /// Converts a linear value to a gamma-encoded value using a gamma value of 2.2. /// @@ -389,7 +237,6 @@ public static class MathUtility return 1.0f / (1.0f + System.Math.Exp(-value)); } -#if NET7_0_OR_GREATER /// /// Applies a simple bias function to value. /// @@ -474,5 +321,4 @@ public static class MathUtility alpha = -two * alpha * alpha * alpha + three * alpha * alpha; return target * alpha + value * (one - alpha); } -#endif } diff --git a/X10D/src/Math/NumberExtensions.cs b/X10D/src/Math/NumberExtensions.cs index 3a058c5..a03d583 100644 --- a/X10D/src/Math/NumberExtensions.cs +++ b/X10D/src/Math/NumberExtensions.cs @@ -1,4 +1,3 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.Contracts; using System.Numerics; using System.Runtime.CompilerServices; @@ -101,4 +100,3 @@ public static class NumberExtensions return TNumber.Sign(value); } } -#endif diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index de64ee3..40b45e6 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -10,112 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class SByteExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 8-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this sbyte value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 32-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte DigitalRoot(this sbyte value) - { - int root = System.Math.Abs(value).Mod(9); - return (sbyte)(root < 1 ? 9 - root : root); - } - - /// - /// Returns the factorial of the current 8-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this sbyte value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (ushort i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 8-bit signed integer, and another 8-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte GreatestCommonFactor(this sbyte value, sbyte other) - { - return (sbyte)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this sbyte value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this sbyte value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -143,30 +37,6 @@ public static class SByteExtensions return (sbyte)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead - /// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte Mod(this sbyte dividend, sbyte divisor) - { - int r = dividend % divisor; - return (sbyte)(r < 0 ? r + divisor : r); - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index 617ed9d..ada7d97 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -10,107 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt16Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 16-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this ushort value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of the current 16-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort DigitalRoot(this ushort value) - { - var root = (ushort)(value % 9); - return (ushort)(root == 0 ? 9 : root); - } - - /// - /// Returns the factorial of the current 16-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this ushort value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (ushort i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 16-bit unsigned integer, and another 16-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort GreatestCommonFactor(this ushort value, ushort other) - { - return (ushort)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this ushort value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this ushort value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index da391e9..c20a19d 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -10,107 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt32Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 32-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this uint value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of the current 32-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint DigitalRoot(this uint value) - { - uint root = value % 9; - return root == 0 ? 9 : root; - } - - /// - /// Returns the factorial of the current 32-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this uint value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (var i = 1U; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 32-bit unsigned integer, and another 32-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint GreatestCommonFactor(this uint value, uint other) - { - return (uint)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this uint value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this uint value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index aaec7b4..3f7637c 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -10,112 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt64Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 64-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this ulong value) - { - if (value == 0) - { - return 1; - } - - return 1 + (int)System.Math.Floor(System.Math.Log10(System.Math.Abs((double)value))); - } - - /// - /// Computes the digital root of the current 64-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong DigitalRoot(this ulong value) - { - ulong root = value % 9; - return root == 0 ? 9 : root; - } - - /// - /// Returns the factorial of the current 64-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this ulong value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (var i = 1UL; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 64-bit unsigned integer, and another 64-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong GreatestCommonFactor(this ulong value, ulong other) - { - while (other != 0) - { - (value, other) = (other, value % other); - } - - return value; - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this ulong value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this ulong value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Text/CharExtensions.cs b/X10D/src/Text/CharExtensions.cs index 8b015de..5ac29ee 100644 --- a/X10D/src/Text/CharExtensions.cs +++ b/X10D/src/Text/CharExtensions.cs @@ -18,13 +18,9 @@ public static class CharExtensions [MethodImpl(CompilerResources.MaxOptimization)] public static bool IsEmoji(this char value) { -#if NET7_0_OR_GREATER Span chars = stackalloc char[1]; chars[0] = value; return EmojiRegex.Value.IsMatch(chars); -#else - return EmojiRegex.Value.IsMatch(value.ToString()); -#endif } /// diff --git a/X10D/src/Text/RuneExtensions.cs b/X10D/src/Text/RuneExtensions.cs index c1f3ef9..24991bb 100644 --- a/X10D/src/Text/RuneExtensions.cs +++ b/X10D/src/Text/RuneExtensions.cs @@ -101,11 +101,7 @@ public static class RuneExtensions default: string exceptionFormat = ExceptionMessages.UnexpectedRuneUtf8SequenceLength; string message = string.Format(CultureInfo.CurrentCulture, exceptionFormat, length); -#if NET7_0_OR_GREATER throw new UnreachableException(message); -#else - throw new InvalidOperationException(message); -#endif // dotcover enable } } diff --git a/tools/Benchmarks/Benchmarks.csproj b/tools/Benchmarks/Benchmarks.csproj index 197c37b..09df3b4 100644 --- a/tools/Benchmarks/Benchmarks.csproj +++ b/tools/Benchmarks/Benchmarks.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 Release Exe true