Skip to content

Commit

Permalink
perf: remove redundant 6k ± 1 check in IsPrime
Browse files Browse the repository at this point in the history
No integers >3 satisfy the condition of being odd AND not being a multiple of 3 (as checked above) AND not being in the form 6k ± 1. This condition never evaluates to true, and so the return is never reached and was preventing this method from hitting 100% code coverage.
  • Loading branch information
oliverbooth committed Mar 31, 2023
1 parent c8ccb1d commit e70781e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 10 deletions.
5 changes: 0 additions & 5 deletions X10D/src/Math/Int64Extensions.cs
Expand Up @@ -148,11 +148,6 @@ public static bool IsPrime(this long value)
return false;
}

if ((value + 1) % 6 != 0 && (value - 1) % 6 != 0)
{
return false;
}

for (var iterator = 5L; iterator * iterator <= value; iterator += 6)
{
if (value % iterator == 0 || value % (iterator + 2) == 0)
Expand Down
5 changes: 0 additions & 5 deletions X10D/src/Math/UInt64Extensions.cs
Expand Up @@ -125,11 +125,6 @@ public static bool IsPrime(this ulong value)
return false;
}

if ((value + 1) % 6 != 0 && (value - 1) % 6 != 0)
{
return false;
}

for (var iterator = 5UL; iterator * iterator <= value; iterator += 6)
{
if (value % iterator == 0 || value % (iterator + 2) == 0)
Expand Down

0 comments on commit e70781e

Please sign in to comment.