diff --git a/src/anchoredinterval.jl b/src/anchoredinterval.jl index 9a66d4a0..da98e9d8 100644 --- a/src/anchoredinterval.jl +++ b/src/anchoredinterval.jl @@ -132,7 +132,14 @@ function Base.last(interval::AnchoredInterval{P}) where P end anchor(interval::AnchoredInterval) = interval.anchor -span(interval::AnchoredInterval{P}) where P = abs(P) + +function span(interval::AnchoredInterval{P}) where P + if !isunbounded(interval) + abs(P) + else + throw(ArgumentError("Unable to determine the span of an unbounded interval")) + end +end ##### CONVERSION ##### diff --git a/src/interval.jl b/src/interval.jl index 99aa1ef4..6c4af654 100644 --- a/src/interval.jl +++ b/src/interval.jl @@ -123,7 +123,15 @@ end Base.first(interval::Interval) = interval.first Base.last(interval::Interval) = interval.last -span(interval::Interval) = interval.last - interval.first + +function span(interval::Interval) + if !isunbounded(interval) + interval.last - interval.first + else + throw(ArgumentError("Unable to determine the span of an unbounded interval")) + end +end + inclusivity(interval::AbstractInterval{T,L,R}) where {T,L,R} = Inclusivity(L === Closed, R === Closed) isclosed(interval::AbstractInterval) = isclosed(inclusivity(interval)) Base.isopen(interval::AbstractInterval) = isopen(inclusivity(interval))