From 4b62ac8332f2ebea1005b7a50ab12c7b030012fc Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Thu, 23 May 2024 00:54:19 -0500 Subject: [PATCH 1/4] Fast intersection for BareInterval (#649) --- src/intervals/interval_operations/set_operations.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/intervals/interval_operations/set_operations.jl b/src/intervals/interval_operations/set_operations.jl index 931265abd..1dcff556e 100644 --- a/src/intervals/interval_operations/set_operations.jl +++ b/src/intervals/interval_operations/set_operations.jl @@ -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)...) From c7d7d819002cdbc50bd3fcee976b288fdd3671f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9not?= <38465572+OlivierHnt@users.noreply.github.com> Date: Fri, 24 May 2024 19:26:46 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Add=20`=E2=8A=94`=20and=20`=E2=8A=93`=20uni?= =?UTF-8?q?code=20alias=20(#651)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/symbols.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/symbols.jl b/src/symbols.jl index 4248d2ce6..ebf20f634 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -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) + """ ∅ From 960187f6c07a6ba5eb331e63ac7d7321a84a4045 Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Fri, 24 May 2024 20:00:04 +0200 Subject: [PATCH 3/4] Fix display for integers --- src/display.jl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/display.jl b/src/display.jl index 8580252a5..4e2ffd160 100644 --- a/src/display.jl +++ b/src/display.jl @@ -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) # `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) @@ -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) # `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 From 0dde317992abf5504f48b6e7a4352094b5efbeed Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Fri, 24 May 2024 20:14:16 +0200 Subject: [PATCH 4/4] Limit significant digits for large integers --- src/display.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display.jl b/src/display.jl index 4e2ffd160..119e128c2 100644 --- a/src/display.jl +++ b/src/display.jl @@ -295,7 +295,7 @@ function _round_string(x::T, sigdigits::Int, r::RoundingMode) where {T<:Abstract str_x = string(x) 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) # `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-") @@ -314,7 +314,7 @@ function _round_string(x::BigFloat, sigdigits::Int, r::RoundingMode) str_x = string(x) str_digits = split(split(str_x, '.'; limit = 2)[2], 'e'; limit = 2)[1] len = length(str_digits) - if isinteger(x) # `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)