diff --git a/csharp/Platform.Numbers/Bit[T].cs b/csharp/Platform.Numbers/Bit[T].cs index 8e8b752..e74a459 100644 --- a/csharp/Platform.Numbers/Bit[T].cs +++ b/csharp/Platform.Numbers/Bit[T].cs @@ -18,33 +18,74 @@ public static class Bit where T : INumberBase, IShiftOperators private static int BitsSize = NumericType.BitsSize; /// - /// + /// Writes a portion of the source value into the target value at the specified bit position. + /// Записывает часть исходного значения в целевое значение в указанной битовой позиции. /// - /// + /// + /// The target value to write to. + /// Целевое значение для записи. + /// + /// + /// The source value to read from. + /// Исходное значение для чтения. + /// + /// + /// The bit position to start writing at. + /// Битовая позиция для начала записи. + /// + /// + /// The number of bits to write. + /// Количество битов для записи. + /// + /// + /// The target value with the specified bits updated. + /// Целевое значение с обновленными указанными битами. + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T PartialWrite(T target, T source, int shift, int limit) { if (shift < 0) { - shift = 32 + shift; + shift = BitsSize + shift; } if (limit < 0) { - limit = 32 + limit; + limit = BitsSize + limit; } var sourceMask = ~(T.MaxValue << limit) & T.MaxValue; var targetMask = ~(sourceMask << shift); return target & targetMask | (source & sourceMask) << shift; } + + /// + /// Reads a portion of bits from the target value at the specified bit position. + /// Читает часть битов из целевого значения в указанной битовой позиции. + /// + /// + /// The target value to read from. + /// Целевое значение для чтения. + /// + /// + /// The bit position to start reading from. + /// Битовая позиция для начала чтения. + /// + /// + /// The number of bits to read. + /// Количество битов для чтения. + /// + /// + /// The extracted bits as a value. + /// Извлеченные биты в виде значения. + /// public static T PartialRead(T target, int shift, int limit) { if (shift < 0) { - shift = 32 + shift; + shift = BitsSize + shift; } if (limit < 0) { - limit = 32 + limit; + limit = BitsSize + limit; } var sourceMask = ~(T.MaxValue << limit) & T.MaxValue; var targetMask = sourceMask << shift; diff --git a/csharp/Platform.Numbers/Math.cs b/csharp/Platform.Numbers/Math.cs index 84a48b7..47fa9d4 100644 --- a/csharp/Platform.Numbers/Math.cs +++ b/csharp/Platform.Numbers/Math.cs @@ -52,7 +52,7 @@ public static class Math /// public static TLinkAddress Factorial(TLinkAddress n) where TLinkAddress : IUnsignedNumber, IComparisonOperators { - if (n >= TLinkAddress.Zero && n <= TLinkAddress.CreateTruncating(MaximumCatalanIndex)) + if (n >= TLinkAddress.Zero && n <= TLinkAddress.CreateTruncating(MaximumFactorialNumber)) { return TLinkAddress.CreateTruncating(_factorials[ulong.CreateTruncating(n)]); } @@ -101,7 +101,7 @@ public static TLinkAddress Catalan(TLinkAddress n) where TLinkAddr [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsPowerOfTwo(TLinkAddress x) where TLinkAddress : IUnsignedNumber, IBitwiseOperators, IComparisonOperators { - return (x & x - TLinkAddress.One) == TLinkAddress.Zero; + return x > TLinkAddress.Zero && (x & (x - TLinkAddress.One)) == TLinkAddress.Zero; } } } diff --git a/csharp/Platform.Numbers/Platform.Numbers.csproj b/csharp/Platform.Numbers/Platform.Numbers.csproj index 0d7a8b7..ae0000c 100644 --- a/csharp/Platform.Numbers/Platform.Numbers.csproj +++ b/csharp/Platform.Numbers/Platform.Numbers.csproj @@ -4,7 +4,7 @@ LinksPlatform's Platform.Numbers Class Library Konstantin Diachenko Platform.Numbers - 0.9.0 + 0.9.1 Konstantin Diachenko net8 Platform.Numbers @@ -23,7 +23,7 @@ true snupkg latest - Update target framework from net7 to net8. + Fix LGTM alerts: add missing XML documentation, fix hardcoded bit size constants, fix IsPowerOfTwo method for zero values, fix incorrect MaximumCatalanIndex usage in Factorial method. enable