diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index 63bc84faa..262ab8148 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -368,7 +368,8 @@ end function invmod(f::ZZModPolyRingElem, M::ZZModPolyRingElem) if !is_unit(f) r = parent(f)() - i = @ccall libflint.fmpz_mod_poly_invmod(r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int + ff = ZZ() + i = @ccall libflint.fmpz_mod_poly_invmod_f(ff::Ref{ZZRingElem}, r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int if iszero(i) error("not yet implemented") else diff --git a/src/flint/gfp_fmpz_elem.jl b/src/flint/gfp_fmpz_elem.jl index 7d6f828ac..dfc955d47 100644 --- a/src/flint/gfp_fmpz_elem.jl +++ b/src/flint/gfp_fmpz_elem.jl @@ -362,10 +362,13 @@ end function mul!(z::FpFieldElem, x::FpFieldElem, y::ZZRingElem) R = parent(x) - @ccall libflint.fmpz_mod(z.data::Ref{ZZRingElem}, y::Ref{ZZRingElem}, R.n::Ref{ZZRingElem})::Nothing - - @ccall libflint.fmpz_mod_mul(z.data::Ref{ZZRingElem}, x.data::Ref{ZZRingElem}, z.data::Ref{ZZRingElem}, R.ninv::Ref{fmpz_mod_ctx_struct})::Nothing - return z + if z !== x + @ccall libflint.fmpz_mod(z.data::Ref{ZZRingElem}, y::Ref{ZZRingElem}, R.n::Ref{ZZRingElem})::Nothing + @ccall libflint.fmpz_mod_mul(z.data::Ref{ZZRingElem}, x.data::Ref{ZZRingElem}, z.data::Ref{ZZRingElem}, R.ninv::Ref{fmpz_mod_ctx_struct})::Nothing + return z + else + return mul!(z, x, R(y)) + end end function add!(z::FpFieldElem, x::FpFieldElem, y::FpFieldElem) diff --git a/test/flint/fmpz_mod_poly-test.jl b/test/flint/fmpz_mod_poly-test.jl index b4db6f577..c6f8b729c 100644 --- a/test/flint/fmpz_mod_poly-test.jl +++ b/test/flint/fmpz_mod_poly-test.jl @@ -343,6 +343,12 @@ end @test powermod(f, -10, g) == 78305338116088931412*x+91239060941924718463 @test powermod(f, -ZZRingElem(10), g) == 78305338116088931412*x+91239060941924718463 + + R, = residue_ring(ZZ, ZZ(2809)) + Rx, x = R[:x] + f = 32*x^9 + 28*x^8 + 2497*x^7 + 2443*x^6 + 708*x^5 + 996*x^4 + 2557*x^3 + 2104*x^2 + 2517*x + 2752 + g = x^10 + 2798*x^8 + 2806*x^7 + 37*x^6 + 14*x^5 + 2761*x^4 + 2787*x^3 + 20*x^2 + 12*x + 1 + @test_throws ErrorException invmod(f, g) end @testset "ZZModPolyRingElem.euclidean_division" begin diff --git a/test/flint/gfp_fmpz-test.jl b/test/flint/gfp_fmpz-test.jl index 1216be268..29c1b418f 100644 --- a/test/flint/gfp_fmpz-test.jl +++ b/test/flint/gfp_fmpz-test.jl @@ -532,3 +532,10 @@ end R = Native.GF(ZZ(19)) @test R([5]) == R(5) end + +@testset "gfp_fmpz.bug" begin + R = Native.GF(ZZRingElem(123456789012345678949)) + z = R(1) + mul!(z, z, ZZ(10)) + @test z == 10 +end