Extract divisor validator and rename legacy CPU prime helper

This commit is contained in:
Marek Lemańczyk committed 2025-10-26 18:59:07 +01:00
1 parent 1e5eadac34
commit 3758524450
11 files changed
+67 -61

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
using System.Runtime.CompilerServices;
namespace PerfectNumbers.Core;
internal static class DivisorGenerator
{
private const ushort DecimalMaskWhenLastIsSeven = (1 << 3) | (1 << 7) | (1 << 9);
private const ushort DecimalMaskOtherwise = (1 << 1) | (1 << 3) | (1 << 9);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsValidDivisor(
byte remainder10,
byte remainder8,
byte remainder3,
byte remainder5,
byte remainder7,
byte remainder11,
LastDigit lastDigit)
{
ushort decimalMask = lastDigit == LastDigit.Seven ? DecimalMaskWhenLastIsSeven : DecimalMaskOtherwise;
if (((decimalMask >> remainder10) & 1) == 0)
{
return false;
}
if (remainder8 != 1 && remainder8 != 7)
{
return false;
}
if (remainder3 == 0 || remainder5 == 0 || remainder7 == 0 || remainder11 == 0)
{
return false;
}
return true;
}
}