Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfExtendedReal can accidentally support a simultaneously positive/negative inf #23

Closed
omus opened this issue Jul 29, 2020 · 0 comments · Fixed by #24
Closed

InfExtendedReal can accidentally support a simultaneously positive/negative inf #23

omus opened this issue Jul 29, 2020 · 0 comments · Fixed by #24

Comments

@omus
Copy link
Contributor

omus commented Jul 29, 2020

I've encountered an issue that only occurs on Linux 64-bit. Using Julia 1.4.2, Infinity 0.2.0, and Intervals 1.4.0 you can reproduce this issue:

julia> using Intervals, Infinity

julia> v = [
           [
               Interval{Closed, Open}(l, u),
               Interval{Open, Open}(l, u),
           ]
           for (l, u) in [(-∞, Inf)]
       ];

julia> v[1]
2-element Array{Interval{InfExtendedReal{Float64},L,Open} where L<:Bound,1}:
 Interval{InfExtendedReal{Float64},Closed,Open}(InfExtendedReal{Float64}(-∞), InfExtendedReal{Float64}(∞))
 Interval{InfExtendedReal{Float64},Open,Open}(InfExtendedReal{Float64}(∞), InfExtendedReal{Float64}(∞))

julia> x = first(b)
InfExtendedReal{Float64}(∞)

julia> Infinity.isposinf(x)
true

julia> Infinity.isneginf(x)
true

julia> x.flag
NEGINF::InfFlag = 0x02

julia> x.finitevalue
Inf

In attempting to reduce the problem further I came up with:

julia> function demo()
           l, u = InfExtendedReal{Float64}(-∞), InfExtendedReal{Float64}(Inf)
           a = Interval{InfExtendedReal{Float64}, Closed, Open}(l, u)
           b = Interval{InfExtendedReal{Float64}, Open, Open}(l, u)
           return first(b)
       end
demo (generic function with 1 method)

julia> y = demo()
InfExtendedReal{Float64}(∞)

julia> Infinity.isposinf(y)
true

julia> Infinity.isneginf(y)
true

julia> y.flag
NEGINF::InfFlag = 0x02

julia> y.finitevalue
Inf

There seems to be a couple of issues here but the main one is that an InfExtendedReal{Float64} can be simultaneously positive and negative infinity at the same time. The source of this problem appears to occur in the InfExtendedReal(::Infinite) constructor when we leave the finitevalue field undefined. If the undefined bits end up representing Inf where the sign differs from the flag field then this problem occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant