Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loop for finding large prime values #2126

Merged
merged 1 commit into from
Oct 14, 2021

Conversation

gsjaardema
Copy link
Contributor

If the val passed to findPrimeGreaterThan is greater than the largest value (not the sentinel) in the NC_primes, then the routine will fall into an infinite loop. Modified to call an external routine that brute forces the finding of a prime larger than the value in this case.

The brute force routine uses the primes in NC_primes table in the prime test, so this will fail if given a value > 180503 * 180503. The isPrime function could be rewritten to avoid this, but assuming this won't happen for the forseeable future. If it does happen, isPrime will return that any value larger than this is prime...

If the `val` passed to `findPrimeGreaterThan` is greater than the largest value (not the sentinel) in the `NC_primes`, then the routine will fall into an infinite loop.   Modified to call an external routine that brute forces the finding of a prime larger than the value in this case.  

The brute force routine uses the primes in `NC_primes` table in the prime test, so this will fail if given a `value > 180503 * 180503`.   The `isPrime` function could be rewritten to avoid this, but assuming this won't happen for the forseeable future.  If it does happen, `isPrime` will return that any value larger than this is prime...
Copy link
Member

@WardF WardF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch!

@WardF WardF merged commit 9116700 into Unidata:main Oct 14, 2021
@gsjaardema gsjaardema deleted the patch-49 branch October 14, 2021 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants