Skip to content

Commit bbc6128

Browse files
committed
Cleanup
1 parent 471a226 commit bbc6128

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/intervals/arithmetic/basic.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ Implement the `sqrt` function of the IEEE Standard 1788-2015 (Table 9.1).
239239
"""
240240
function Base.sqrt(x::BareInterval{T}) where {T<:AbstractFloat}
241241
sup(x) < 0 && return emptyinterval(BareInterval{T})
242-
lo = inf(x) < 0 ? zero(T) : inf(x)
242+
lo = _cut_negative_domain(x)
243243
return @round(T, sqrt(lo), sqrt(sup(x)))
244244
end
245+
_cut_negative_domain(x::BareInterval{T}) where {T<:AbstractFloat} = ifelse(inf(x) < 0, zero(T), inf(x))
246+
_cut_negative_domain(x::BareInterval{T}) where {T<:BigFloat} = inf(x) < 0 ? zero(T) : inf(x)
245247

246248
Base.sqrt(x::BareInterval{<:Rational}) = sqrt(float(x))
247249

src/intervals/construction.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ Internal constructor which assumes that `is_valid_interval(lo, hi) == true`.
7878
_unsafe_bareinterval(::Type{T}, a, b) where {T<:NumTypes} =
7979
_unsafe_bareinterval(T, _round(T, a, RoundDown), _round(T, b, RoundUp))
8080

81-
_normalisezero(a) = ifelse(iszero(a), zero(a), a) # Avoid branch in general
82-
_normalisezero(a::BigFloat) = iszero(a) ? zero(a) : a # For BigFloat we avoid the allocation as much as possible
81+
_normalisezero(a) = ifelse(iszero(a), zero(a), a)
82+
_normalisezero(a::BigFloat) = iszero(a) ? zero(a) : a # avoid allocation for BigFloat
8383
# used only to construct intervals; needed to avoid `inf` and `sup` normalization
8484
_inf(x::BareInterval) = x.lo
8585
_sup(x::BareInterval) = x.hi

src/intervals/interval_operations/numeric.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Implement the `inf` function of the IEEE Standard 1788-2015 (Table 9.2).
1414
See also: [`sup`](@ref), [`bounds`](@ref), [`mid`](@ref), [`diam`](@ref),
1515
[`radius`](@ref) and [`midradius`](@ref).
1616
"""
17-
function inf(x::BareInterval{T}) where {T<:AbstractFloat}
18-
isnan(x.lo) && return typemax(T)
17+
inf(x::BareInterval{T}) where {T<:AbstractFloat} = ifelse(isnan(x.lo), typemax(T), ifelse(iszero(x.lo), copysign(x.lo, -1), x.lo))
18+
function inf(x::BareInterval{T}) where {T<:BigFloat}
19+
isnan(x.lo) && return typemax(T) # typemax(x.lo)
1920
iszero(x.lo) && return copysign(x.lo, -1)
2021
return x.lo
2122
end
@@ -43,8 +44,9 @@ Implement the `sup` function of the IEEE Standard 1788-2015 (Table 9.2).
4344
See also: [`inf`](@ref), [`bounds`](@ref), [`mid`](@ref), [`diam`](@ref),
4445
[`radius`](@ref) and [`midradius`](@ref).
4546
"""
46-
function sup(x::BareInterval{T}) where {T<:AbstractFloat}
47-
isnan(x.hi) && return typemin(T)
47+
sup(x::BareInterval{T}) where {T<:AbstractFloat} = ifelse(isnan(x.hi), typemin(T), x.hi)
48+
function sup(x::BareInterval{T}) where {T<:BigFloat}
49+
isnan(x.hi) && return typemin(T) # typemin(x.hi)
4850
return x.hi
4951
end
5052

0 commit comments

Comments
 (0)