From a89ea9e3f964a6f0b61eee7daffc3b386f3af556 Mon Sep 17 00:00:00 2001 From: deva567 <40196767+deva567@users.noreply.github.com> Date: Fri, 19 Jun 2020 19:41:14 +0530 Subject: [PATCH 1/2] update Primes.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier primes(0) will through like "The condition lo ≤ hi must be met." but primes(0) will return output as look like primes(0,0). --- src/Primes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Primes.jl b/src/Primes.jl index 2a0e075..a6b8bb0 100644 --- a/src/Primes.jl +++ b/src/Primes.jl @@ -127,7 +127,7 @@ function primes(lo::Int, hi::Int) end return list end -primes(n::Int) = primes(1, n) +primes(n::Int) = primes(0, n) const PRIMES = primes(2^16) From 9d27bf95dff98ca2e4593ab6dec9ff7847b075c1 Mon Sep 17 00:00:00 2001 From: deva567 <40196767+deva567@users.noreply.github.com> Date: Sun, 21 Jun 2020 14:54:39 +0530 Subject: [PATCH 2/2] Updation on Primes function The Primes() will accept now one parameter which may be the negative or positive integer. --- src/Primes.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Primes.jl b/src/Primes.jl index a6b8bb0..a4ff42e 100644 --- a/src/Primes.jl +++ b/src/Primes.jl @@ -112,6 +112,9 @@ primesmask(n::Integer) = n ≤ typemax(Int) ? primesmask(Int(n)) : Returns a collection of the prime numbers (from `lo`, if specified) up to `hi`. """ function primes(lo::Int, hi::Int) + if hi<1 + list=Int[] + else lo ≤ hi || throw(ArgumentError("The condition lo ≤ hi must be met.")) list = Int[] lo ≤ 2 ≤ hi && push!(list, 2) @@ -125,6 +128,7 @@ function primes(lo::Int, hi::Int) @inbounds for i = 1:length(sieve) # don't use eachindex here sieve[i] && push!(list, wheel_prime(i + lwi)) end + end return list end primes(n::Int) = primes(0, n)