From b23476deb4a4d06492a3390c55f75f91048b763d Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Sun, 12 Dec 2021 22:43:23 -0600 Subject: [PATCH 1/7] Fix display of -0.0 to 0.0 --- src/display.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/display.jl b/src/display.jl index 152ce7a17..1ba04a14a 100644 --- a/src/display.jl +++ b/src/display.jl @@ -185,6 +185,8 @@ function basic_representation(a::Interval, format=nothing) local output + a = Interval(_signofzero(a.lo), a.hi) + if format == :standard aa = round_string(a.lo, sigfigs, RoundDown) @@ -219,6 +221,8 @@ function basic_representation(a::Interval{Float32}, format=nothing) local output + a = Interval(_signofzero(a.lo), a.hi) + if format == :standard aa = round_string(a.lo, sigfigs, RoundDown) @@ -268,6 +272,8 @@ function basic_representation(a::Interval{Rational{T}}, format=nothing) where output end +@inline _signofzero(a::Real) = ifelse(iszero(a) && signbit(a), copysign(a, 1), a) + function subscriptify(n::Integer) dig = reverse(digits(n)) subscript_0 = Int('₀') # 0x2080 From 495a7a21f9a3df75267f5cc5f30cb9b9e7caf021 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 13 Dec 2021 20:19:42 -0600 Subject: [PATCH 2/7] Add _normalisezero (instead of _signofzero) and fix display of inf --- src/display.jl | 6 ------ src/intervals/arithmetic.jl | 2 +- src/intervals/intervals.jl | 7 +++++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/display.jl b/src/display.jl index 1ba04a14a..152ce7a17 100644 --- a/src/display.jl +++ b/src/display.jl @@ -185,8 +185,6 @@ function basic_representation(a::Interval, format=nothing) local output - a = Interval(_signofzero(a.lo), a.hi) - if format == :standard aa = round_string(a.lo, sigfigs, RoundDown) @@ -221,8 +219,6 @@ function basic_representation(a::Interval{Float32}, format=nothing) local output - a = Interval(_signofzero(a.lo), a.hi) - if format == :standard aa = round_string(a.lo, sigfigs, RoundDown) @@ -272,8 +268,6 @@ function basic_representation(a::Interval{Rational{T}}, format=nothing) where output end -@inline _signofzero(a::Real) = ifelse(iszero(a) && signbit(a), copysign(a, 1), a) - function subscriptify(n::Integer) dig = reverse(digits(n)) subscript_0 = Int('₀') # 0x2080 diff --git a/src/intervals/arithmetic.jl b/src/intervals/arithmetic.jl index 721f61cc5..ebb9b47e0 100644 --- a/src/intervals/arithmetic.jl +++ b/src/intervals/arithmetic.jl @@ -302,7 +302,7 @@ end # Infimum and supremum of an interval -inf(a::Interval) = a.lo +inf(a::Interval) = ifelse(iszero(a.lo) && !signbit(a.lo), copysign(a.lo, -1), a.lo) sup(a::Interval) = a.hi diff --git a/src/intervals/intervals.jl b/src/intervals/intervals.jl index 3507e6e2f..5dc1259f5 100644 --- a/src/intervals/intervals.jl +++ b/src/intervals/intervals.jl @@ -20,9 +20,10 @@ struct Interval{T<:Real} <: AbstractInterval{T} function Interval{T}(a::Real, b::Real) where T<:Real if validity_check - + a = _normalisezero(a) + b = _normalisezero(b) if is_valid_interval(a, b) - new(a, b) + return new(a, b) else @warn "Invalid input, empty interval is returned" @@ -36,6 +37,8 @@ struct Interval{T<:Real} <: AbstractInterval{T} end end +@inline _normalisezero(a::Real) = ifelse(iszero(a) && signbit(a), copysign(a, 1), a) +@inline _normalisezero(a::Integer) = float(a) ## Outer constructors From 89feefe649250773bf67e3ca64930b29f17d1fc8 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 14 Dec 2021 08:41:25 -0600 Subject: [PATCH 3/7] Reposition use of _normalisezero --- src/intervals/intervals.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/intervals/intervals.jl b/src/intervals/intervals.jl index 5dc1259f5..55140f6d7 100644 --- a/src/intervals/intervals.jl +++ b/src/intervals/intervals.jl @@ -19,9 +19,11 @@ struct Interval{T<:Real} <: AbstractInterval{T} function Interval{T}(a::Real, b::Real) where T<:Real + a = _normalisezero(a) + b = _normalisezero(b) + if validity_check - a = _normalisezero(a) - b = _normalisezero(b) + if is_valid_interval(a, b) return new(a, b) @@ -38,7 +40,7 @@ struct Interval{T<:Real} <: AbstractInterval{T} end @inline _normalisezero(a::Real) = ifelse(iszero(a) && signbit(a), copysign(a, 1), a) -@inline _normalisezero(a::Integer) = float(a) +@inline _normalisezero(a::Integer) = _normalisezero(float(a)) ## Outer constructors From 2a956789bea90c09cc5efb90f99ffdaa7fc01e53 Mon Sep 17 00:00:00 2001 From: lucaferranti Date: Tue, 14 Dec 2021 19:25:18 +0200 Subject: [PATCH 4/7] fix atan2 for decorated intervals --- src/decorations/functions.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/decorations/functions.jl b/src/decorations/functions.jl index 8f3e2907b..4ece02b51 100644 --- a/src/decorations/functions.jl +++ b/src/decorations/functions.jl @@ -314,8 +314,9 @@ function atan(yy::DecoratedInterval{T}, xx::DecoratedInterval{T}) where T # Check cases when decoration is trv and decays (from com or dac) if zero(T) ∈ y zero(T) ∈ x && return DecoratedInterval(r, trv) - if x.hi < zero(T) && y.lo != y.hi && signbit(y.lo) && Int(d) > 2 - return DecoratedInterval(r, decay(d)) + if x.hi < zero(T) + signbit(y.lo) && return DecoratedInterval(r, min(d, def)) + return DecoratedInterval(r, min(d, dac)) end end DecoratedInterval(r, d) From 816cd99986ecf44ecf6a55680dbad4c12d1f5bf3 Mon Sep 17 00:00:00 2001 From: lucaferranti Date: Tue, 14 Dec 2021 19:37:28 +0200 Subject: [PATCH 5/7] small update --- src/decorations/functions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decorations/functions.jl b/src/decorations/functions.jl index 4ece02b51..7594a3843 100644 --- a/src/decorations/functions.jl +++ b/src/decorations/functions.jl @@ -315,7 +315,7 @@ function atan(yy::DecoratedInterval{T}, xx::DecoratedInterval{T}) where T if zero(T) ∈ y zero(T) ∈ x && return DecoratedInterval(r, trv) if x.hi < zero(T) - signbit(y.lo) && return DecoratedInterval(r, min(d, def)) + y.lo < zero(T) && return DecoratedInterval(r, min(d, def)) return DecoratedInterval(r, min(d, dac)) end end From 99b8fd2490d86d18267c262e2093e3b8c87eb8ee Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 14 Dec 2021 12:18:04 -0600 Subject: [PATCH 6/7] Clean-up _normalisezero --- src/intervals/intervals.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/intervals/intervals.jl b/src/intervals/intervals.jl index 55140f6d7..47525863a 100644 --- a/src/intervals/intervals.jl +++ b/src/intervals/intervals.jl @@ -40,7 +40,6 @@ struct Interval{T<:Real} <: AbstractInterval{T} end @inline _normalisezero(a::Real) = ifelse(iszero(a) && signbit(a), copysign(a, 1), a) -@inline _normalisezero(a::Integer) = _normalisezero(float(a)) ## Outer constructors From 820105871dcb1605be1c46368bec2743a6bce1b3 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 14 Dec 2021 12:38:39 -0600 Subject: [PATCH 7/7] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 599f0e48c..701647b4c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IntervalArithmetic" uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git" -version = "0.20.1" +version = "0.20.2" [deps] CRlibm = "96374032-68de-5a5b-8d9e-752f78720389"