Skip to content

Commit

Permalink
Prevent unbound return value
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Dec 1, 2023
1 parent 50c394c commit 4984e40
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/galois/_prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,16 @@ def prev_prime(n: int) -> int:

shifts = [29, 23, 19, 17, 13, 11, 7, 1] # Factorization wheel for basis {2, 3, 5}
base = n // 30 * 30 # Wheel factorization starting point
found = False # Success flag

while not found:
while True:
for shift in shifts:
i = base + shift # May be bigger than n
if i >= n:
continue
if is_prime(i):
found = True
break
return i
base -= 30

return i


@export
def next_prime(n: int) -> int:
Expand Down Expand Up @@ -219,20 +215,16 @@ def next_prime(n: int) -> int:

shifts = [1, 7, 11, 13, 17, 19, 23, 29] # Factorization wheel for basis {2, 3, 5}
base = n // 30 * 30 # Wheel factorization starting point. May be less than n.
found = False # Success flag

while not found:
while True:
for shift in shifts:
i = base + shift
if i <= n:
continue
if is_prime(i):
found = True
break
return i
base += 30

return i


@export
def random_prime(bits: int, seed: int | None = None) -> int:
Expand Down

0 comments on commit 4984e40

Please sign in to comment.