forked from JuliaIntervals/IntervalArithmetic.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add IntervalSets conversions (JuliaIntervals#677)
* add IntervalSets conversions * upd Project * fixes * upd * more careful conversion
- Loading branch information
1 parent
1bc70c6
commit ffad210
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module IntervalArithmeticsIntervalSetsExt | ||
|
||
import IntervalSets as IS | ||
import IntervalArithmetic as IA | ||
|
||
IA.interval(i::IS.Interval{L,R,T}) where {L,R,T} = IA.interval(IA.promote_numtype(T, T), i) | ||
function IA.interval(::Type{T}, i::IS.Interval{L,R}) where {T<:IA.NumTypes,L,R} | ||
# infinite endpoints are always open in IA, finite always closed: | ||
isinf(IS.leftendpoint(i)) != IS.isleftopen(i) && return IA.nai(T) | ||
isinf(IS.rightendpoint(i)) != IS.isrightopen(i) && return IA.nai(T) | ||
x = IA.interval(T, IS.endpoints(i)...) | ||
return IA._unsafe_interval(IA.bareinterval(x), IA.decoration(x), false) | ||
end | ||
|
||
function IS.Interval(i::IA.Interval) | ||
lo, hi = IA.bounds(i) | ||
# infinite endpoints are always open in IA, finite always closed: | ||
L = ifelse(isinf(lo), :open, :closed) | ||
R = ifelse(isinf(hi), :open, :closed) | ||
return IS.Interval{L,R}(lo, hi) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[deps] | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | ||
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters