diff --git a/src/number/n_Zp.jl b/src/number/n_Zp.jl index 87d92cad1..5be6e5d56 100644 --- a/src/number/n_Zp.jl +++ b/src/number/n_Zp.jl @@ -295,6 +295,27 @@ promote_rule(C::Type{n_Zp}, ::Type{n_Z}) = n_Zp # take ownership of the pointer - not for general users (R::N_ZpField)(n::libSingular.number_ptr) = n_Zp(R, n) +function (F::N_ZpField)(a::Nemo.fpFieldElem) + characteristic(F) == characteristic(parent(a)) || error("characteristic does not match") + return F(lift(a)) +end + +function (F::N_ZpField)(a::Nemo.zzModRingElem) + characteristic(F) == characteristic(parent(a)) || error("characteristic does not match") + return F(lift(a)) +end + +function (F::Nemo.fpField)(a::n_Zp) + characteristic(F) == characteristic(parent(a)) || error("characteristic does not match") + return F(Int(a)) +end + +function (F::Nemo.zzModRing)(a::n_Zp) + characteristic(F) == characteristic(parent(a)) || error("characteristic does not match") + return F(Int(a)) +end + + ############################################################################### # # Fp constructor diff --git a/test/libsingular/nemo-test.jl b/test/libsingular/nemo-test.jl index f155dc227..699c6be6e 100644 --- a/test/libsingular/nemo-test.jl +++ b/test/libsingular/nemo-test.jl @@ -367,6 +367,30 @@ end @test string(p) == "0" @test length(p) == 0 @test is_zero(p) + + R = residue_ring(Nemo.ZZ, 7) + F = Fp(7) + for i in -10:10 + @test R(one(F)*i) == one(R)*i + @test F(one(R)*i) == one(F)*i + end + + S = Nemo.GF(5) + @test_throws ErrorException S(one(F)) + @test_throws ErrorException F(one(S)) +end + +@testset "Nemo.fpFieldElem" begin + R = Nemo.GF(7) + F = Fp(7) + for i in -10:10 + @test R(one(F)*i) == one(R)*i + @test F(one(R)*i) == one(F)*i + end + + S = Nemo.GF(5) + @test_throws ErrorException S(one(F)) + @test_throws ErrorException F(one(S)) end @testset "Nemo.ZZModRingElem" begin