Skip to content

Commit 8abee0d

Browse files
committed
Use promotion in default isapprox methods
1 parent b8de597 commit 8abee0d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/NCRings.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ end
103103
# hand, we need isapprox methods to be able to conformance test series rings.
104104
# On the other hand this is essentially the only sensible thing to do in
105105
# positive characteristic so we might as well do it in a generic method.
106-
function Base.isapprox(x::NCRingElem, y::NCRingElem;
106+
function Base.isapprox(x::T, y::T;
107107
atol::Real=0, rtol::Real=0,
108-
nans::Bool=false, norm::Function=abs)
108+
nans::Bool=false, norm::Function=abs) where {T <: NCRingElem}
109109
if is_exact_type(typeof(x)) && is_exact_type(typeof(y))
110110
@req is_zero(atol) "non-zero atol not supported"
111111
@req is_zero(rtol) "non-zero rtol not supported"
@@ -114,6 +114,21 @@ function Base.isapprox(x::NCRingElem, y::NCRingElem;
114114
throw(NotImplementedError(:isapprox, x, y))
115115
end
116116

117+
function Base.isapprox(x::NCRingElem, y::NCRingElem; kwarg...)
118+
fl, u, v = try_promote(x, y)
119+
if fl
120+
return isapprox(u, v; kwarg...)
121+
end
122+
throw(NotImplementedError(:isapprox, x, y))
123+
end
124+
125+
Base.isapprox(x::NCRingElem, y::Union{Integer, Rational, AbstractFloat}; kwarg...)
126+
= isapprox(x, parent(x)(y); kwarg...)
127+
128+
Base.isapprox(x::Union{Integer, Rational, AbstractFloat}, y::NCRingElem; kwarg...)
129+
= isapprox(parent(y)(x), y; kwarg...)
130+
131+
117132
function divexact_left(x::NCRingElem, y::NCRingElem; check::Bool = true)
118133
return divexact_left(promote(x, y)...)
119134
end

0 commit comments

Comments
 (0)