I would like to have a infinite range, the code do not return error, but have a NaN. This can easily create bugs in program.
julia> a = -Inf:Inf
-Inf:1.0:NaN
versioninfo()
Julia Version 0.5.1-pre+31
Commit 6a1e339* (2016-11-17 17:50 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
WORD_SIZE: 64
BLAS: libmkl_rt
LAPACK: libmkl_rt
LIBM: libimf
LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
This should probably be an error.
What do you expect your range to do?
I would expect an infinity range as an initialization.
the expected output should be exactly: -Inf:1.0:Inf
What would that mean though? How long would it be? What values would you
get when iterating over it?
On 18 May 2017 4:51 pm, "Jingpeng Wu" notifications@github.com wrote:
I would expect an infinity range as an initialization.
the expected output should be exactly: -Inf:Infโ
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/JuliaLang/julia/issues/21941#issuecomment-302446949,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABnRaafRQBtC4YaAq-eZBDMQTjLv1w8Xks5r7GjygaJpZM4Nfa7K
.
These should be an error on construction. There's no sensible meaning to such ranges.
Maybe you are looking for an infinite interval, rather than a range.
This is available in e.g. the IntervalArithmetic.jl
package:
julia> using IntervalArithmetic
julia> X = -โ..โ # .. constructs intervals of real numbers
[-โ, โ]
julia> 1.5e15 โ X
true
julia> typeof(X)
IntervalArithmetic.Interval{Float64}
-Inf:Inf
is an error since 0.5.1
Inf:Inf
is an error on v0.6.0-rc1
Julia-0.5.0> -Inf:Inf
-Inf:1.0:NaN
Julia-0.5.1> -Inf:Inf
ERROR: InexactError()
in trunc(::Type{Int64}, ::Float64) at .\float.jl:463
in colon(::Float64, ::Float64, ::Float64) at .\range.jl:183
in colon(::Float64, ::Float64) at .\range.jl:191
md5-9933ee6d569eb12697615ec87fa3e9d4
Julia-0.5.2> Inf:Inf
Inf:1.0:Inf
md5-9933ee6d569eb12697615ec87fa3e9d4
Julia-0.6.0-rc1> Inf:Inf
ERROR: InexactError()
Stacktrace:
[1] trunc(::Type{Int64}, ::Float64) at .\float.jl:672
[2] colon(::Float64, ::Float64, ::Float64) at .\twiceprecision.jl:156
[3] colon(::Float64, ::Float64) at .\range.jl:67
not that the 0.5.0 behavior is that useful, but that's a bit more of a behavior change between 0.5.0 and 0.5.1 than I usually would have preferred for backporting. any guesses which backport commit it was?
Someone is welcome to figure out a way to restore the pre-0.5.2 behavior without breaking what that change fixed but it does not seem important enough to me to warrant much effort.
Looks like this be closed now? Or is there any work / discussion remaining?
Most helpful comment
Maybe you are looking for an infinite interval, rather than a range.
This is available in e.g. the
IntervalArithmetic.jl
package: