Remove cancellation-aware UInt128 ModPow overload
This commit is contained in:
1 parent
c892e1c30c
commit
0f51454496
2 files changed
+38
-38
No files matched your search
@@ -560,43 +560,6 @@ public static class UInt128Extensions
|
||||
public static ulong Mod128(this UInt128 value) => (ulong)value & 127UL;
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static UInt128 ModPow(this UInt128 value, UInt128 exponent, UInt128 modulus, CancellationToken ct)
|
||||
{
|
||||
UInt128 zero = UInt128.Zero;
|
||||
UInt128 one = UInt128.One;
|
||||
if (modulus <= one)
|
||||
{
|
||||
return zero;
|
||||
}
|
||||
|
||||
UInt128 result = UInt128.One;
|
||||
UInt128 baseValue = value % modulus;
|
||||
|
||||
while (exponent != zero)
|
||||
{
|
||||
if (ct.IsCancellationRequested)
|
||||
{
|
||||
return zero;
|
||||
}
|
||||
|
||||
if ((exponent & one) != zero)
|
||||
{
|
||||
result = result.MulMod(baseValue, modulus);
|
||||
}
|
||||
|
||||
if (ct.IsCancellationRequested)
|
||||
{
|
||||
return zero;
|
||||
}
|
||||
|
||||
baseValue = baseValue.MulMod(baseValue, modulus);
|
||||
exponent >>= 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static UInt128 ModPow(this UInt128 value, UInt128 exponent, UInt128 modulus)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user