Skip to content

Commit a87fb27

Browse files
committed
Implement boundstype
1 parent 09ac4da commit a87fb27

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

src/decorations/intervals.jl

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,7 @@ end
3434
DecoratedInterval(I::DecoratedInterval, dec::DECORATION) = DecoratedInterval(I.interval, dec)
3535

3636
function DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:Real, S<:Real}
37-
BoundsType = promote_type(default_bound(), T, S)
38-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
39-
return DecoratedInterval(Interval{BoundsType}(a, b), d)
40-
end
41-
function DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:AbstractFloat, S<:Real}
42-
BoundsType = promote_type(T, S)
43-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
44-
return DecoratedInterval(Interval{BoundsType}(a, b), d)
45-
end
46-
function DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:Real, S<:AbstractFloat}
47-
BoundsType = promote_type(T, S)
48-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
49-
return DecoratedInterval(Interval{BoundsType}(a, b), d)
50-
end
51-
function DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:AbstractFloat, S<:AbstractFloat}
52-
BoundsType = promote_type(T, S)
37+
BoundsType = boundstype(T, S)
5338
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
5439
return DecoratedInterval(Interval{BoundsType}(a, b), d)
5540
end
@@ -67,22 +52,7 @@ end
6752
DecoratedInterval(I::Interval) = DecoratedInterval{default_bound()}(I)
6853

6954
function DecoratedInterval(a::T, b::S) where {T<:Real, S<:Real}
70-
BoundsType = promote_type(default_bound(), T, S)
71-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
72-
return DecoratedInterval(Interval{BoundsType}(a, b))
73-
end
74-
function DecoratedInterval(a::T, b::S) where {T<:AbstractFloat, S<:Real}
75-
BoundsType = promote_type(T, S)
76-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
77-
return DecoratedInterval(Interval{BoundsType}(a, b))
78-
end
79-
function DecoratedInterval(a::T, b::S) where {T<:Real, S<:AbstractFloat}
80-
BoundsType = promote_type(T, S)
81-
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
82-
return DecoratedInterval(Interval{BoundsType}(a, b))
83-
end
84-
function DecoratedInterval(a::T, b::S) where {T<:AbstractFloat, S<:AbstractFloat}
85-
BoundsType = promote_type(T, S)
55+
BoundsType = boundstype(T, S)
8656
is_valid_interval(a, b) || return DecoratedInterval(Interval{BoundsType}(a, b), ill)
8757
return DecoratedInterval(Interval{BoundsType}(a, b))
8858
end

src/intervals/construction.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Interval{Float64}
3434
"""
3535
default_bound() = Float64
3636

37+
# Produce the type of the bounds of an interval when not explicitly imposed
38+
boundstype(::Type{T}, ::Type{S}) where {T<:AbstractFloat, S<:AbstractFloat} = promote_type(T, S)
39+
boundstype(::Type{T}, ::Type{S}) where {T<:AbstractFloat, S} = promote_type(T, S)
40+
boundstype(::Type{T}, ::Type{S}) where {T, S<:AbstractFloat} = promote_type(T, S)
41+
boundstype(::Type{T}, ::Type{S}) where {T, S} = promote_type(default_bound(), T, S)
42+
3743
@inline _normalisezero(a::Real) = ifelse(iszero(a), zero(a), a)
3844

3945
"""
@@ -88,11 +94,7 @@ function interval(::Type{T}, a, b) where {T}
8894
@warn "Invalid input, empty interval is returned"
8995
return emptyinterval(T)
9096
end
91-
interval(a::T, b::S) where {T<:AbstractFloat, S<:AbstractFloat} =
92-
interval(promote_type(T, S), a, b)
93-
interval(a::T, b::S) where {T<:AbstractFloat, S} = interval(promote_type(T, S), a, b)
94-
interval(a::T, b::S) where {T, S<:AbstractFloat} = interval(promote_type(T, S), a, b)
95-
interval(a::T, b::S) where {T, S} = interval(promote_type(default_bound(), T, S), a, b)
97+
interval(a::T, b::S) where {T, S} = interval(boundstype(T, S), a, b)
9698

9799
# Real: `is_valid_interval(a, a) != true`
98100
interval(::Type{T}, a::Real) where {T} = interval(T, a, a)

0 commit comments

Comments
 (0)