Skip to content

Commit

Permalink
Use promotion in default isapprox methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 18, 2024
1 parent b8de597 commit 8abee0d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/NCRings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 8abee0d

Please sign in to comment.