Skip to content

Commit

Permalink
Return explicitly an NaI for intersection and hull (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt authored May 31, 2024
1 parent f043cfd commit 09af634
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/intervals/interval_operations/numeric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ not normalize the infimum of the interval.
See also: [`inf`](@ref), [`sup`](@ref), [`mid`](@ref), [`diam`](@ref),
[`radius`](@ref) and [`midradius`](@ref).
"""
bounds(x::BareInterval{T}) where {T<:AbstractFloat} = (ifelse(isnan(x.lo), typemax(T), x.lo), x.hi)
bounds(x::BareInterval{T}) where {T<:AbstractFloat} = (ifelse(isnan(x.lo), typemax(T), x.lo), sup(x))
bounds(x::BareInterval{<:Rational}) = (inf(x), sup(x))

function bounds(x::Interval{T}) where {T<:AbstractFloat}
Expand Down
11 changes: 6 additions & 5 deletions src/intervals/interval_operations/set_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Implement the `intersection` function of the IEEE Standard 1788-2015 (Section 9.
function intersect_interval(x::BareInterval{T}, y::BareInterval{T}) where {T<:NumTypes}
lo = max(inf(x), inf(y))
hi = min(sup(x), sup(y))

if lo > hi
return emptyinterval(BareInterval{T})
else
Expand All @@ -25,9 +24,10 @@ function intersect_interval(x::BareInterval{T}, y::BareInterval{T}) where {T<:Nu
end
intersect_interval(x::BareInterval, y::BareInterval) = intersect_interval(promote(x, y)...)

function intersect_interval(x::Interval, y::Interval)
function intersect_interval(x::Interval{T}, y::Interval{S}) where {T<:NumTypes,S<:NumTypes}
isnai(x) | isnai(y) && return nai(promote_type(T, S))
r = intersect_interval(bareinterval(x), bareinterval(y))
d = min(decoration(x), decoration(y), decoration(r), trv)
d = min(decoration(x), decoration(y), trv)
t = isguaranteed(x) & isguaranteed(y)
return _unsafe_interval(r, d, t)
end
Expand All @@ -54,9 +54,10 @@ function hull(x::BareInterval{T}, y::BareInterval{T}) where {T<:NumTypes}
end
hull(x::BareInterval, y::BareInterval) = hull(promote(x, y)...)

function hull(x::Interval, y::Interval)
function hull(x::Interval{T}, y::Interval{S}) where {T<:NumTypes,S<:NumTypes}
isnai(x) | isnai(y) && return nai(promote_type(T, S))
r = hull(bareinterval(x), bareinterval(y))
d = min(decoration(x), decoration(y), decoration(r), trv)
d = min(decoration(x), decoration(y), trv)
t = isguaranteed(x) & isguaranteed(y)
return _unsafe_interval(r, d, t)
end
Expand Down

0 comments on commit 09af634

Please sign in to comment.