|
1 | 1 | module IntervalSets
|
2 | 2 |
|
3 | 3 | using Base: @pure
|
4 |
| -import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, |
| 4 | +import Base: eltype, convert, show, in, length, isempty, isequal, isapprox, issubset, ==, hash, |
5 | 5 | union, intersect, minimum, maximum, extrema, range, clamp, mod, float, ⊇, ⊊, ⊋
|
6 | 6 |
|
7 | 7 | using Statistics
|
@@ -142,6 +142,16 @@ isequal(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) & ise
|
142 | 142 | ==(A::TypedEndpointsInterval{L,R}, B::TypedEndpointsInterval{L,R}) where {L,R} = (leftendpoint(A) == leftendpoint(B) && rightendpoint(A) == rightendpoint(B)) || (isempty(A) && isempty(B))
|
143 | 143 | ==(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) && isempty(B)
|
144 | 144 |
|
| 145 | +function isapprox(A::AbstractInterval, B::AbstractInterval; atol=0, rtol=Base.rtoldefault(eltype(A), eltype(B), atol), kwargs...) |
| 146 | + closedendpoints(A) != closedendpoints(B) && error("Comparing intervals with different closedness is not defined") |
| 147 | + isempty(A) != isempty(B) && return false |
| 148 | + isempty(A) && isempty(B) && return true |
| 149 | + maxabs = max(maximum(abs, endpoints(A)), maximum(abs, endpoints(B))) |
| 150 | + let atol = max(atol, rtol * maxabs) |
| 151 | + isapprox(leftendpoint(A), leftendpoint(B); atol, rtol, kwargs...) && isapprox(rightendpoint(A), rightendpoint(B); atol, rtol, kwargs...) |
| 152 | + end |
| 153 | +end |
| 154 | + |
145 | 155 | function issubset(A::TypedEndpointsInterval, B::TypedEndpointsInterval)
|
146 | 156 | Al, Ar = endpoints(A)
|
147 | 157 | Bl, Br = endpoints(B)
|
|
0 commit comments