Relax ulong multiply-shift guards and refresh tests

This commit is contained in:
Marek Lemańczyk committed 2025-10-04 22:40:18 +02:00
1 parent 38df505f4f
commit 75586d07b8
3 files changed
+2 -48

No files matched your search

-25
View File
@@ -59,22 +59,12 @@ public static class ULongExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetBitLength(this ulong value)
{
if (value == 0UL)
{
return 0;
}
return 64 - BitOperations.LeadingZeroCount(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong MultiplyShiftRight(ulong value, ulong multiplier, int shift)
{
if (shift < 0)
{
throw new ArgumentOutOfRangeException(nameof(shift), "Shift must be non-negative.");
}
UInt128 product = (UInt128)value * multiplier;
return (ulong)(product >> shift);
}
@@ -82,21 +72,6 @@ public static class ULongExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong MultiplyShiftRightShiftFirst(ulong value, ulong multiplier, int shift)
{
if (shift < 0)
{
throw new ArgumentOutOfRangeException(nameof(shift), "Shift must be non-negative.");
}
if (shift == 0)
{
return MultiplyShiftRight(value, multiplier, 0);
}
if (shift >= 64)
{
return 0UL;
}
ulong high = value >> shift;
ulong mask = (1UL << shift) - 1UL;
ulong low = value & mask;