Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: InexactError: trunc(Int64, NaN) when multiplying zero with range in Julia v0.7 #29079

Closed
zsoerenm opened this issue Sep 7, 2018 · 2 comments

Comments

@zsoerenm
Copy link
Contributor

zsoerenm commented Sep 7, 2018

If I multiply zero with a range: 0.0 .* (1:8000) in Julia v0.7, I get the folliowing error:

ERROR: InexactError: trunc(Int64, NaN)
Stacktrace:
 [1] trunc at ./float.jl:693 [inlined]
 [2] round at ./float.jl:359 [inlined]
 [3] floatrange(::Type{Float64}, ::Int64, ::Int64, ::Int64, ::Int64) at ./twiceprecision.jl:361
 [4] _range(::Float64, ::Float64, ::Nothing, ::Int64) at ./twiceprecision.jl:435
 [5] #range#29 at ./range.jl:76 [inlined]
 [6] #range at ./none:0 [inlined]
 [7] broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(*), ::Float64, ::UnitRange{Int64}) at ./broadcast.jl:977
 [8] broadcasted(::Function, ::Float64, ::UnitRange{Int64}) at ./broadcast.jl:1141
 [9] top-level scope at none:0

This did not happen in v0.6.

Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

Workaround for now is: 0.0 .* collect(1:8000)

BTW if 0 is a Int, it produces the following error:

julia> 0 .* (1:8000)
ERROR: ArgumentError: step cannot be zero
Stacktrace:
 [1] steprange_last(::Int64, ::Int64, ::Int64) at ./range.jl:190
 [2] Type at ./range.jl:180 [inlined]
 [3] _rangestyle at ./range.jl:93 [inlined]
 [4] _range at ./range.jl:91 [inlined]
 [5] #range#29 at ./range.jl:76 [inlined]
 [6] #range at ./none:0 [inlined]
 [7] broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(*), ::Int64, ::UnitRange{Int64}) at ./broadcast.jl:977
 [8] broadcasted(::Function, ::Int64, ::UnitRange{Int64}) at ./broadcast.jl:1141
 [9] top-level scope at none:0
@fredrikekre
Copy link
Member

There is an open PR that fixes this: #29056

@zsoerenm
Copy link
Contributor Author

I will close this as #29056 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants