JuliaMath / JuliaMath/Infinities.jl
`RealInfinity` is abstract, but the package assumes it has exactly two subtypes
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 22
- Forks
- 10
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 7
Description
RealInfinity is declared abstract and exported, which invites downstream subtypes:
abstract type RealInfinity <: Real end
struct PositiveInfinity <: RealInfinity end
struct NegativeInfinity <: RealInfinity end
However signbit is defined only on the two concrete types, with no ::RealInfinity fallback, and sign, angle and every T(x::RealInfinity) conversion are built on it:
signbit(::PositiveInfinity) = false # src/Infinities.jl:52-53
signbit(::NegativeInfinity) = true
sign(y::RealInfinity) = 1-2signbit(y) # :71
angle(x::RealInfinity) = π*signbit(x) # :72
_convert(::Type{T}, x::RealInfinity) where {T<:Real} = sign(x)*convert(T, Inf) # :64
So a third subtype does not fail cleanly:
julia> struct ThirdInfinity <: Infinities.RealInfinity end
julia> signbit(ThirdInfinity())
ERROR: StackOverflowError:
julia> Float64(ThirdInfinity())
ERROR: StackOverflowError:
It falls through to Base.signbit(x::Real) = x < 0 (number.jl:137) and the comparison then recurses.
Two ways to make the assumption explicit:
-
Non-breaking — add a
signbit(::RealInfinity)fallback that throws a clear error, so an unsupported subtype produces a message instead of a stack overflow. -
Breaking — put the closure in the type system:
struct PositiveInfinity <: Real end struct NegativeInfinity <: Real end const RealInfinity = Union{PositiveInfinity, NegativeInfinity}
The second option is what was probably intended, at least if the intent is that the extended real line has exactly two points at infinity — with directional infinities living in ComplexInfinity{T} — then option 2 states that in the type system rather than in convention.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Infinities.jl at the signbit methods and RealInfinity-dependent sign, angle, and conversion definitions. Reproduce the ThirdInfinity examples to confirm the recursive failure, then determine whether the project intends a rejecting fallback or a closed type representation. Done means unsupported subtypes fail clearly or the two-infinity constraint is enforced, with regression coverage for the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100