--gpu-ration command-line argument added. AscendingDivisorRemainderStepper implemented in PrimeTester.IsPrimeCpu. PrimeOrderCalculator.RunOnCpu adjusted for low GPU ratios to prevent infinite increase of the counter.
This commit is contained in:
1 parent
f43c67c86f
commit
85a90c70bf
9 files changed
+296
-212
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
public struct AscendingDivisorRemainderStepper
|
||||
{
|
||||
private readonly ulong dividend;
|
||||
private ulong maxDivisor;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AscendingDivisorRemainderStepper(ulong value)
|
||||
{
|
||||
dividend = value;
|
||||
ulong root = (ulong)Math.Sqrt(value);
|
||||
if ((UInt128)root * root < value)
|
||||
{
|
||||
root++;
|
||||
}
|
||||
|
||||
maxDivisor = root;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool ShouldContinue(ulong divisor) => divisor <= maxDivisor;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Divides(ulong divisor)
|
||||
{
|
||||
ulong quotient = dividend / divisor;
|
||||
ulong remainder = dividend - (quotient * divisor);
|
||||
if (quotient < maxDivisor)
|
||||
{
|
||||
maxDivisor = quotient;
|
||||
}
|
||||
|
||||
return remainder == 0UL;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user