File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,12 @@ function _primesmask(lo::Int, hi::Int)
63
63
if small_sieve[i]
64
64
p = wheel_prime (i)
65
65
j = wheel_index (2 * div (lo - p - 1 , 2 p) + 1 )
66
- q = p * wheel_prime (j + 1 )
66
+ r = widemul (p, wheel_prime (j + 1 ))
67
+ r > m && continue # use widemul to avoid r <= m caused by overflow
67
68
j = j & 7 + 1
68
- while q ≤ m
69
+ q = Int (r)
70
+ # q < 0 indicates overflow when incrementing q inside loop
71
+ while 0 ≤ q ≤ m
69
72
sieve[wheel_index (q) - wlo] = false
70
73
q += wheel[j] * p
71
74
j = j & 7 + 1
Original file line number Diff line number Diff line change 451
451
@test Base. IteratorEltype (prevprimes (10 )) == Base. HasEltype ()
452
452
@test Base. IteratorSize (prevprimes (10 )) == Base. SizeUnknown ()
453
453
end
454
+
455
+ @testset " primes with huge arguments" begin
456
+ if Base. Sys. WORD_SIZE == 64
457
+ @test primes (2 ^ 63 - 200 , 2 ^ 63 - 1 ) == [9223372036854775643 , 9223372036854775783 ]
458
+ end
459
+ @test primes (2 ^ 31 - 20 , 2 ^ 31 - 1 ) == [2147483629 , 2147483647 ]
460
+ end
You can’t perform that action at this time.
0 commit comments