Skip to content

Commit 93676b9

Browse files
committed
Use atol as default ztol in isapprox
1 parent d12533b commit 93676b9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/comparison.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ isapproxzero(p::APL; kwargs...) = all(isapproxzero.(terms(p); kwargs...))
110110
isapproxzero(p::RationalPoly; kwargs...) = isapproxzero(p.num; kwargs...)
111111

112112
Base.isapprox(t1::AbstractTerm, t2::AbstractTerm; kwargs...) = isapprox(coefficient(t1), coefficient(t2); kwargs...) && monomial(t1) == monomial(t2)
113-
Base.isapprox(p1::AbstractPolynomial, p2::AbstractPolynomial; ztol::Real=1e-6, kwargs...) = compare_terms(p1, p2, t -> isapproxzero(t; ztol=ztol), (x, y) -> isapprox(x, y; kwargs...))
113+
function Base.isapprox(p1::AbstractPolynomial{S}, p2::AbstractPolynomial{T};
114+
atol=0, ztol::Real=iszero(atol) ? Base.rtoldefault(S, T, 0) : atol, kwargs...) where {S, T}
115+
return compare_terms(p1, p2, t -> isapproxzero(t; ztol=ztol),
116+
(x, y) -> isapprox(x, y; atol=atol, kwargs...))
117+
end
114118

115119
Base.isapprox(p::RationalPoly, q::RationalPoly; kwargs...) = isapprox(p.num*q.den, q.num*p.den; kwargs...)
116120
Base.isapprox(p::RationalPoly, q::APL; kwargs...) = isapprox(p.num, q*p.den; kwargs...)

test/REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
BenchmarkTools
2-
DynamicPolynomials 0.1.3
2+
DynamicPolynomials 0.1.4
33
TypedPolynomials 0.2

test/comparison.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
@test isapprox((2-1e-3)*x*y + (3+1e-3)*y^2, 3*y^2 + 2*y*x, rtol=1e-2)
5151
@test !isapprox((2-1e-3)*x*y + (3+1e-1)*y^2, 3*y^2 + 2*y*x, rtol=1e-2)
5252
@test isapprox(1e-3*x*y + 3*y^2 + x^2, x^2 + 3*y^2, rtol=1e-2, ztol=1e-2)
53+
@test isapprox(1e-3*x*y + 3*y^2 + x^2, x^2 + 3*y^2, rtol=1e-2, atol=1e-2)
5354
@test isapprox(3*y^2 + x^2, x^2 + 1e-3*x*y + 3*y^2, rtol=1e-2, ztol=1e-2)
55+
@test isapprox(3*y^2 + x^2, x^2 + 1e-3*x*y + 3*y^2, rtol=1e-2, atol=1e-2)
5456
@test !isapprox(3*y^2 + x^2, x^2 + 1e-1*x*y + 3*y^2, rtol=1e-2, ztol=1e-2)
5557
@test !isapprox(3.0*y^2 + x + x^2, x + 3*y^2, rtol=1e-2, ztol=1e-2)
5658
@test isapprox(x+1-x, 1+1e-8, rtol=1e-7)

0 commit comments

Comments
 (0)