JuliaMath / Primes.jl

Prime numbers in Julia
Other
99 stars 32 forks source link

The iterator `eachfactor` is not type-stable #151

Closed byhill closed 8 months ago

byhill commented 8 months ago

Consider the following code.

julia> eltype(eachfactor(Int32(901800900)))
Tuple{Int32, Int64}

julia> for (p, e) in eachfactor(Int32(901800900))
       println()
       println((p, typeof(p)))
       println((e, typeof(e)))
       end

(2, Int32)
(2, Int64)

(3, Int64)
(2, Int64)

(5, Int64)
(2, Int64)

(7, Int64)
(2, Int64)

(11, Int32)
(2, Int64)

(13, Int32)
(2, Int64)

The eachfactor iterator should return (at least based on it's eltype) Tuple{Int32,Int64} but it returns a mixture of Tuple{Int32,Int64} and Tuple{Int64,Int64}.

oscardssmith commented 8 months ago

ah good catch. This was mostly tested on Int64 inputs. Fixing this should be pretty easy.

oscardssmith commented 8 months ago

fixed and version tagged (Pkg should know about it in ~1 hr)