diff --git a/Project.toml b/Project.toml index 3bb67ab2..86605ebe 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Ripserer" uuid = "aa79e827-bd0b-42a8-9f10-2b302677a641" authors = ["mtsch "] -version = "0.16.11" +version = "0.16.12" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/base/primefield.jl b/src/base/primefield.jl index 95eefafa..b33bcf0d 100644 --- a/src/base/primefield.jl +++ b/src/base/primefield.jl @@ -4,7 +4,7 @@ Return `true` if `n` is a prime number. """ -Base.@pure function is_prime(n::Int) +function is_prime(n::Int) if iseven(n) || n < 2 return n == 2 else @@ -81,6 +81,13 @@ Base.zero(::Type{Mod{M}}) where {M} = Mod{M}(0, false) Base.one(::Type{Mod{M}}) where {M} = Mod{M}(1, false) Base.sign(i::M) where {M<:Mod} = ifelse(iszero(i), zero(M), one(M)) -Base.promote_rule(::Type{Mod{M}}, ::Type{<:Integer}) where {M} = Mod{M} +Base.promote_rule(::Type{Mod{M}}, ::Type{<:Mod}) where {M} = Union{} +function Base.promote_rule(::Type{Mod{M}}, ::Type{I}) where {M,I<:Integer} + if Base.promote_type(I, Int128) === Int128 || Base.promote_type(I, Int128) === UInt128 + return Mod{M} + else + return Union{} + end +end Base.inv(i::Mod{M}) where {M} = Mod{M}(invmod(Int(i), M), false) diff --git a/test/base/primefield.jl b/test/base/primefield.jl index a720d352..52ef8214 100644 --- a/test/base/primefield.jl +++ b/test/base/primefield.jl @@ -53,7 +53,7 @@ end @test_throws ErrorException Mod{3}(1) < Mod{3}(2) @test_throws ErrorException Mod{3}(1) ≥ Mod{3}(2) - @test_throws StackOverflowError Mod{3}(1) + Mod{2}(1) + @test_throws ErrorException Mod{3}(1) + Mod{2}(1) end @testset "Printing" begin