Skip to content

Commit 1754eec

Browse files
authored
Revert throwing an error for non-thin intervals (#625)
1 parent ba420dc commit 1754eec

File tree

2 files changed

+11
-60
lines changed

2 files changed

+11
-60
lines changed

src/intervals/interval_operations/boolean.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ Test whether `x` contains only `y`.
348348
"""
349349
isthin(x::BareInterval, y::Number) = inf(x) == sup(x) == y
350350
isthin(x::BareInterval, y::Complex) = isthin(x, real(y)) & iszero(imag(y))
351-
isthin(x::BareInterval, y::Interval) = throw(MethodError(isthin, (x, y)))
351+
isthin(::BareInterval, ::Interval) =
352+
throw(ArgumentError("`isthin` is purposely not supported for intervals. See instead `isequal_interval`"))
352353

353354
function isthin(x::Interval, y::Number)
354355
isnai(x) && return false

src/intervals/real_interface.jl

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -137,71 +137,21 @@ end
137137
==(::Number, ::Interval)
138138
139139
Test whether an interval is the singleton of a given number. In other words, the
140-
result is true if and only if the interval contains only that number. This
141-
function errors whenever the input interval is not a singleton.
140+
result is true if and only if the interval contains only that number.
142141
143142
!!! note
144143
Comparison between intervals is purposely disallowed. Indeed, equality
145144
between non-singleton intervals has distinct properties, notably ``x = y``
146145
does not imply ``x - y = 0``. See instead [`isequal_interval`](@ref).
147146
"""
148-
function Base.:(==)(x::BareInterval, y::Number)
149-
isthin(x) || return throw(ArgumentError("`==` is only supported between thin intervals and numbers"))
150-
return inf(x) == y
151-
end
152-
Base.:(==)(x::Number, y::BareInterval) = y == x
153-
function Base.:(==)(x::Interval, y::Number)
154-
isnai(x) && return false
155-
return bareinterval(x) == y
156-
end
157-
Base.:(==)(x::Number, y::Interval) = y == x
158-
Base.:(==)(x::BareInterval, y::Interval) = throw(MethodError(==, (x, y)))
159-
Base.:(==)(x::Interval, y::BareInterval) = throw(MethodError(==, (x, y)))
147+
Base.:(==)(x::Union{BareInterval,Interval}, y::Number) = isthin(x, y)
148+
Base.:(==)(x::Number, y::Union{BareInterval,Interval}) = y == x
160149

161-
"""
162-
iszero(::BareInterval)
163-
iszero(::Interval)
150+
# follows docstring of `Base.iszero`
151+
Base.iszero(x::Union{BareInterval,Interval}) = isthinzero(x)
164152

165-
Test whether an interval is the singleton of zero. This function errors whenever
166-
the input interval is not a singleton.
167-
"""
168-
function Base.iszero(x::BareInterval)
169-
isthin(x) || return throw(ArgumentError("`iszero` is only supported for thin intervals"))
170-
return iszero(inf(x))
171-
end
172-
function Base.iszero(x::Interval)
173-
isnai(x) && return false
174-
return iszero(bareinterval(x))
175-
end
176-
177-
"""
178-
isone(::BareInterval)
179-
isone(::Interval)
153+
# follows docstring of `Base.isone`
154+
Base.isone(x::Union{BareInterval,Interval}) = isthinone(x)
180155

181-
Test whether an interval is the singleton of one. This function errors whenever
182-
the input interval is not a singleton.
183-
"""
184-
function Base.isone(x::BareInterval)
185-
isthin(x) || return throw(ArgumentError("`isone` is only supported for thin intervals"))
186-
return isone(inf(x))
187-
end
188-
function Base.isone(x::Interval)
189-
isnai(x) && return false
190-
return isone(bareinterval(x))
191-
end
192-
193-
"""
194-
isinteger(::BareInterval)
195-
isinteger(::Interval)
196-
197-
Test whether an interval is the singleton of an integer. This function errors
198-
whenever the input interval is not a singleton.
199-
"""
200-
function Base.isinteger(x::BareInterval)
201-
isthin(x) || return throw(ArgumentError("`isinteger` is only supported for thin intervals"))
202-
return isinteger(inf(x))
203-
end
204-
function Base.isinteger(x::Interval)
205-
isnai(x) && return false
206-
return isinteger(bareinterval(x))
207-
end
156+
# follows docstring of `Base.isinteger`
157+
Base.isinteger(x::Union{BareInterval,Interval}) = isthininteger(x)

0 commit comments

Comments
 (0)