Skip to content

Commit

Permalink
Minor tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Oct 12, 2024
1 parent e54b6a9 commit 5c633ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/intervals/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ isguaranteed(x::Complex{<:Interval}) = isguaranteed(real(x)) & isguaranteed(imag

isguaranteed(::Number) = false

Interval{T}(x::Interval) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve method ambiguity
Interval{T}(x::Real) where {T<:NumTypes} = convert(Interval{T}, x)
Interval(x::Real) = Interval{promote_numtype(typeof(x), typeof(x))}(x)

#

"""
Expand Down Expand Up @@ -563,6 +559,10 @@ Base.promote_rule(::Type{T}, ::Type{Interval{S}}) where {T<:AbstractIrrational,S

# conversion

Interval{T}(x::Real) where {T<:NumTypes} = convert(Interval{T}, x)
Interval(x::Real) = Interval{promote_numtype(numtype(x), numtype(x))}(x)
Interval{T}(x::Interval) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve method ambiguity

Base.convert(::Type{Interval{T}}, x::Interval) where {T<:NumTypes} = interval(T, x)

function Base.convert(::Type{Interval{T}}, x::Complex{<:Interval}) where {T<:NumTypes}
Expand Down
7 changes: 5 additions & 2 deletions src/intervals/exact_literals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ Base.promote_rule(::Type{ExactReal{T}}, ::Type{ExactReal{S}}) where {T<:Real,S<:

# to BareInterval

BareInterval{T}(x::ExactReal) where {T<:NumTypes} = convert(BareInterval{T}, x)
BareInterval(x::ExactReal) = BareInterval{promote_numtype(numtype(x.value), numtype(x.value))}(x)

Base.convert(::Type{BareInterval{T}}, x::ExactReal) where {T<:NumTypes} = bareinterval(T, x.value)

Base.promote_rule(::Type{BareInterval{T}}, ::Type{ExactReal{S}}) where {T<:NumTypes,S<:Real} =
Expand All @@ -106,8 +109,8 @@ Base.promote_rule(::Type{ExactReal{T}}, ::Type{Interval{S}}) where {T<:Real,S<:N
# to Real

(::Type{T})(x::ExactReal) where {T<:Real} = convert(T, x)
Interval{T}(x::ExactReal) where {T<:NumTypes} = convert(Interval{T}, x) # to resolve ambiguity
Interval(x::ExactReal) = Interval{promote_numtype(typeof(x.value), typeof(x.value))}(x) # to resolve ambiguity
Interval{T}(x::ExactReal) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve ambiguity
Interval(x::ExactReal) = Interval{promote_numtype(numtype(x.value), numtype(x.value))}(x) # needed to resolve ambiguity

Base.convert(::Type{T}, x::ExactReal) where {T<:Real} = convert(T, x.value)

Expand Down

0 comments on commit 5c633ee

Please sign in to comment.