diff --git a/src/flint/fmpq_poly.jl b/src/flint/fmpq_poly.jl index 4ed63eb51..c7e07b358 100644 --- a/src/flint/fmpq_poly.jl +++ b/src/flint/fmpq_poly.jl @@ -446,7 +446,15 @@ function Base.div(x::QQPolyRingElem, y::QQPolyRingElem) return z end -divexact(x::QQPolyRingElem, y::QQPolyRingElem; check::Bool=true) = div(x,y) +function divexact(x::QQPolyRingElem, y::QQPolyRingElem; check::Bool=true) + if !check + return div(x, y) + else + q, r = divrem(x, y) + !iszero(r) && throw(ArgumentError("not an exact division")) + return q + end +end ############################################################################### # diff --git a/test/flint/fmpq_poly-test.jl b/test/flint/fmpq_poly-test.jl index 514686655..fe847b1ef 100644 --- a/test/flint/fmpq_poly-test.jl +++ b/test/flint/fmpq_poly-test.jl @@ -361,6 +361,10 @@ end f = 3*y^2 + 7*y + 3 + @test divexact(f, f) == one(S) + + @test_throws ArgumentError divexact(f, y) + @test divexact(3*f, 3) == f @test divexact(ZZRingElem(3)*f, ZZRingElem(3)) == f