Feature or bug? (1:3).*0

julia> (1:3)*0

ERROR: ArgumentError: step cannot be zero

Stacktrace:

[1] steprange_last( ::Int64, ::Int64, ::Int64 ) at ./range.jl:190

[2] _rangestyle at ./range.jl:180 [inlined]

[3] _range at ./range.jl:91 [inlined]

[4] #range#29 at ./range.jl:76 [inlined]

[5] #range at ./none:0 [inlined]

[6] broadcasted at ./broadcast.jl:982 [inlined]

[7] broadcasted at ./broadcast.jl:1142 [inlined]

[8] broadcast at ./broadcast.jl:702 [inlined]

[9] *( ::UnitRange{Int64}, ::Int64 ) at ./arraymath.jl:55

[10] top-level scope at none:0

I’ve had to wrap all ranges in collect() everywhere in my code because otherwise my code is buggy for some input parameters.

That looks like a natural behaviour to me. You may want to use fill(0., 3) instead.

See Diagonal(1:n) cannot be multiplied by zero · Issue #29052 · JuliaLang/julia · GitHub and Improve support for constructing zero-step float ranges by mbauman · Pull Request #29056 · JuliaLang/julia · GitHub

1 Like