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

UnitRange in 1.7-rc1 #42291

Closed
PaulSoderlind opened this issue Sep 17, 2021 · 2 comments · Fixed by #42410
Closed

UnitRange in 1.7-rc1 #42291

PaulSoderlind opened this issue Sep 17, 2021 · 2 comments · Fixed by #42410
Labels
domain:broadcast Applying a function over a collection domain:ranges Everything AbstractRange kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version
Milestone

Comments

@PaulSoderlind
Copy link
Contributor

x = (1:5) .- 1/7 in 1.7-rc1 gives 0.8571428571428572:1.0:3.857142857142857 and length(x) = 4

This is different from 1.6.2, and it also differs from what collect(1:5) .- 1/7 would give.

See Discourse for more details.

@mcabbott
Copy link
Contributor

I believe it goes to this line: https://github.com/JuliaLang/julia/blob/master/base/broadcast.jl#L1106

broadcasted(::DefaultArrayStyle{1}, ::typeof(-), r::AbstractUnitRange, x::Real) = range(first(r) - x, last(r) - x)

last changed in #41619. And length(range(1 - 1/7, 5 - 1/7)) == 4 due to rounding.

@sostock sostock added domain:broadcast Applying a function over a collection domain:ranges Everything AbstractRange kind:regression Regression in behavior compared to a previous version kind:bug Indicates an unexpected problem or unintended behavior labels Sep 17, 2021
@sostock sostock added this to the 1.7 milestone Sep 17, 2021
@PaulSoderlind
Copy link
Contributor Author

Since there are few comments here, let me just add this: I am pretty sure that most users interpret (1:5) .- 1/7 as being the same as range(1,5,length=5) .- 1/7. Motivation: the explicit (1:5).

vtjnash added a commit that referenced this issue Sep 28, 2021
vtjnash added a commit that referenced this issue Sep 29, 2021
KristofferC pushed a commit that referenced this issue Oct 5, 2021
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:broadcast Applying a function over a collection domain:ranges Everything AbstractRange kind:bug Indicates an unexpected problem or unintended behavior kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants