From 9f67d865a8869b9d0ec7deb73e11e5bad1e43700 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Tue, 15 Aug 2023 15:26:05 +0200 Subject: [PATCH] Make `divexact(::fmpq_poly, ::fmpq_poly)` honour the `check` keyword --- src/flint/fmpq_poly.jl | 10 +++++++++- test/flint/fmpq_poly-test.jl | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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