InfiniteArrays.jl icon indicating copy to clipboard operation
InfiniteArrays.jl copied to clipboard

How is `0.0:0.0:∞` handled?

Open putianyi889 opened this issue 1 year ago • 3 comments

Currently this cannot be constructed with colons.

julia> 0.0:0.0:∞
ERROR: ArgumentError: InfStepRange must have infinite length
Stacktrace:
 [1] (::Colon)(start::Float64, step::Float64, stop::Infinities.Infinity)
   @ InfiniteArrays C:\Users\pty\.julia\dev\InfiniteArrays\src\infrange.jl:19
 [2] top-level scope
   @ REPL[40]:1

It can be generated using the type constructor or manipulating ranges.

julia> (1.0:∞)-(1.0:∞)
0.0:0.0:+∞

julia> InfStepRange(0.0,0.0)
0.0:0.0:+∞

julia> InfStepRange(0,0)
0:0:+∞

This is the same strategy that Julia Base uses. StepRangeLen is well defined for this purpose, while InfStepRange is ambiguous on what the stop should be.

julia> (1.0:5.0)-(1.0:5.0)
StepRangeLen(0.0, 0.0, 5)

julia> (1:5)-(1:5)
StepRangeLen(0, 0, 5)

InfUnitRange has a different pipeline.

julia> (1:∞)-(1:∞)
ℵ₀-element Fill{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}} with indices OneToInf(), with entries equal to 0

putianyi889 avatar Mar 15 '23 23:03 putianyi889

There is a case where 0.0:0.0:∞ has a problem, although it doesn't have much to do with the type definitions.

julia> r = InfiniteArrays.InfStepRange(0.0,0.0)
0.0:0.0:+∞

julia> s=-r
-0.0:-0.0:-∞

julia> last(s),last(r)
(-∞, +∞)

julia> s[end],r[end]
(ℵ₀, ℵ₀)

julia> s==r
false

putianyi889 avatar Mar 16 '23 21:03 putianyi889

iszero(0.0:0.0:+∞) currently falls into infinite loop.

putianyi889 avatar Mar 28 '23 11:03 putianyi889

This change is related: https://github.com/JuliaArrays/InfiniteArrays.jl/pull/122

dlfivefifty avatar Mar 28 '23 12:03 dlfivefifty