From 8abee0d6898222541ea76bf06864ae1e6269a4af Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 18 Oct 2024 16:53:10 +0200 Subject: [PATCH] Use promotion in default isapprox methods --- src/NCRings.jl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/NCRings.jl b/src/NCRings.jl index 7a547cb6ff..a75015bf7b 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -103,9 +103,9 @@ end # hand, we need isapprox methods to be able to conformance test series rings. # On the other hand this is essentially the only sensible thing to do in # positive characteristic so we might as well do it in a generic method. -function Base.isapprox(x::NCRingElem, y::NCRingElem; +function Base.isapprox(x::T, y::T; atol::Real=0, rtol::Real=0, - nans::Bool=false, norm::Function=abs) + nans::Bool=false, norm::Function=abs) where {T <: NCRingElem} if is_exact_type(typeof(x)) && is_exact_type(typeof(y)) @req is_zero(atol) "non-zero atol not supported" @req is_zero(rtol) "non-zero rtol not supported" @@ -114,6 +114,21 @@ function Base.isapprox(x::NCRingElem, y::NCRingElem; throw(NotImplementedError(:isapprox, x, y)) end +function Base.isapprox(x::NCRingElem, y::NCRingElem; kwarg...) + fl, u, v = try_promote(x, y) + if fl + return isapprox(u, v; kwarg...) + end + throw(NotImplementedError(:isapprox, x, y)) +end + +Base.isapprox(x::NCRingElem, y::Union{Integer, Rational, AbstractFloat}; kwarg...) + = isapprox(x, parent(x)(y); kwarg...) + +Base.isapprox(x::Union{Integer, Rational, AbstractFloat}, y::NCRingElem; kwarg...) + = isapprox(parent(y)(x), y; kwarg...) + + function divexact_left(x::NCRingElem, y::NCRingElem; check::Bool = true) return divexact_left(promote(x, y)...) end