Julia: NaN in -Inf:Inf

Created on 18 May 2017  ยท  10Comments  ยท  Source: JuliaLang/julia

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)
help wanted

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:

julia> using IntervalArithmetic

julia> X = -โˆž..โˆž   # .. constructs intervals of real numbers
[-โˆž, โˆž]

julia> 1.5e15 โˆˆ X
true

julia> typeof(X)
IntervalArithmetic.Interval{Float64}

All 10 comments

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?

20396 ??

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixrehren picture felixrehren  ยท  3Comments

helgee picture helgee  ยท  3Comments

StefanKarpinski picture StefanKarpinski  ยท  3Comments

wilburtownsend picture wilburtownsend  ยท  3Comments

TotalVerb picture TotalVerb  ยท  3Comments