Skip to content

Commit 7a5c82e

Browse files
committed
make non-allocating
1 parent 4c40652 commit 7a5c82e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Primes.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ function lucas_test(n::T) where T<:Signed
259259
k::T = (n + 1)
260260
trail = trailing_zeros(k)
261261
k >>= trail
262-
for b in digits(k, base=2)[end-1:-1:1]
262+
# get digits 1 at a time since digits allocates
263+
for b in ndigits(p,base=2)-2:-1:0
263264
U = mod(U*V, n)
264265
V = mod(V * V - Qk - Qk, n)
265266
Qk = mod(Qk*Qk, n)
266-
if b == 1
267+
if isodd(k>>b) == 1
267268
Qk = mod(Qk*Q, n)
268269
U, V = U + V, V + U*D
269270
# adding n makes them even

0 commit comments

Comments
 (0)