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 with Float64 * StepRange{Int,Int} with negative step #40846

Closed
jdeldre opened this issue May 17, 2021 · 1 comment · Fixed by #40847
Closed

Error with Float64 * StepRange{Int,Int} with negative step #40846

jdeldre opened this issue May 17, 2021 · 1 comment · Fixed by #40847
Labels
bug Indicates an unexpected problem or unintended behavior ranges Everything AbstractRange

Comments

@jdeldre
Copy link

jdeldre commented May 17, 2021

With the nightly build, I am getting an error when I multiply a StepRange with negative step and a float:

julia> ar = 10:-1:1
10:-1:1

julia> arf = 0.1*ar;

julia> arf[1]
1.0

julia> arf[2]
1.1

I would have gotten arf[2] = 0.9 with previous versions. Note that this only seems to arise with floats multiplying StepRange{Int,Int}. I get expected behavior with, e.g., 0.1*(10.0:-1.0:1.0) and 2*(10:-1:1).

Julia Version 1.7.0-DEV.1109
Commit 0bae193 (2021-05-17 14:08 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.6.0)
CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, haswell)

@dkarrasch dkarrasch added bug Indicates an unexpected problem or unintended behavior ranges Everything AbstractRange labels May 17, 2021
@mcabbott
Copy link
Contributor

mcabbott commented May 17, 2021

That's a bug in #40320 , sorry!

Fix should be simple I think, at https://github.com/JuliaLang/julia/pull/40320/files#diff-d86efa14f136d64b4e87e75251b7164c34a1deb688aa08cf3de54c4ef661bf39R1161-R1162:

julia> 0.1 .* (10:-1:1)
1.0:0.1:1.9

julia> @eval Base.Broadcast broadcasted(::DefaultArrayStyle{1}, ::typeof(*), x::AbstractFloat, r::OrdinalRange) =
            Base.range_start_step_length(x*first(r), x*step(r), length(r));

julia> 0.1 .* (10:-1:1)
1.0:-0.1:0.1

julia> 0.1 .* (3:-1:1) |> collect  # sadly -- but wasn't pretty in 1.6 either
3-element Vector{Float64}:
 0.30000000000000004
 0.20000000000000004
 0.10000000000000003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior ranges Everything AbstractRange
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants