Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dps-export-sqcap
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 26, 2024
2 parents 5125347 + 0dde317 commit fc3ad1d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,11 @@ end

function _round_string(x::T, sigdigits::Int, r::RoundingMode) where {T<:AbstractFloat}
str_x = string(x)
str_digits = split(contains(str_x, '.') ? split(string(x), '.'; limit = 2)[2] : str_x, 'e'; limit = 2)[1]
str_digits = split(contains(str_x, '.') ? split(str_x, '.'; limit = 2)[2] : str_x, 'e'; limit = 2)[1]
len = length(str_digits)
if (isinteger(x) || ispow2(abs(x))) && sigdigits len # `x` is exactly representable
if isinteger(x) && sigdigits len # `x` is exactly representable
return replace(_round_string(big(x), length(str_x), RoundNearest), "e-0" => "e-")
elseif ispow2(abs(x)) && sigdigits len # `x` is exactly representable
return replace(_round_string(big(x), len + 1, RoundNearest), "e-0" => "e-")
else
return _round_string(big(x), sigdigits, r)
Expand All @@ -309,9 +311,12 @@ function _round_string(x::BigFloat, sigdigits::Int, r::RoundingMode)
if !isfinite(x)
return string(Float64(x))
else
str_digits = split(split(string(x), '.'; limit = 2)[2], 'e'; limit = 2)[1]
str_x = string(x)
str_digits = split(split(str_x, '.'; limit = 2)[2], 'e'; limit = 2)[1]
len = length(str_digits)
if (isinteger(x) || ispow2(abs(x))) && sigdigits len # `x` is exactly representable
if isinteger(x) && sigdigits len # `x` is exactly representable
return _round_string(big(x), length(str_x), RoundNearest)
elseif ispow2(abs(x)) && sigdigits len # `x` is exactly representable
return _round_string(big(x), len + 1, RoundNearest)
else
# `sigdigits` digits after the decimal
Expand Down
10 changes: 8 additions & 2 deletions src/intervals/interval_operations/set_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ The result is decorated by at most `trv` (Section 11.7.1).
Implement the `intersection` function of the IEEE Standard 1788-2015 (Section 9.3).
"""
function intersect_interval(x::BareInterval{T}, y::BareInterval{T}) where {T<:NumTypes}
isdisjoint_interval(x, y) && return emptyinterval(BareInterval{T})
return _unsafe_bareinterval(T, max(inf(x), inf(y)), min(sup(x), sup(y)))
lo = max(inf(x), inf(y))
hi = min(sup(x), sup(y))

if lo > hi
return emptyinterval(BareInterval{T})
else
return _unsafe_bareinterval(T, lo, hi)
end
end
intersect_interval(x::BareInterval, y::BareInterval) = intersect_interval(promote(x, y)...)

Expand Down
16 changes: 16 additions & 0 deletions src/symbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ Unicode alias of [`isinterior`](@ref).
"""
(x, y) = isinterior(x, y)

"""
⊔(x, y)
x ⊔ y
Unicode alias of [`hull`](@ref).
"""
(x, y) = hull(x, y)

"""
⊓(x, y)
x ⊓ y
Unicode alias of [`intersect_interval`](@ref).
"""
(x, y) = intersect_interval(x, y)

"""
Expand Down

0 comments on commit fc3ad1d

Please sign in to comment.