JuliaMath / JuliaMath/Infinities.jl

`RealInfinity` is abstract, but the package assumes it has exactly two subtypes

Open
#78 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. Non-breaking — add a signbit(::RealInfinity) fallback that throws a clear error, so an unsupported subtype produces a message instead of a stack overflow.

  2. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.