Skip to content

Commit

Permalink
Calculate correct eltype when multiplying StepRangeLen by Units. (
Browse files Browse the repository at this point in the history
#485)

* Prevent promotion of StepRangeLen eltype when multiplying by unit

* Release 1.9.1
  • Loading branch information
sostock authored Oct 13, 2021
1 parent b471e0d commit d67368a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Unitful"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.9.0"
version = "1.9.1"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down
3 changes: 2 additions & 1 deletion src/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ end

# No need to confuse things by changing the type once units are on there,
# if we can help it.
*(r::StepRangeLen, y::Units) = StepRangeLen(r.ref*y, r.step*y, length(r), r.offset)
*(r::StepRangeLen, y::Units) =
StepRangeLen{typeof(zero(eltype(r))*y)}(r.ref*y, r.step*y, length(r), r.offset)
*(r::LinRange, y::Units) = LinRange(r.start*y, r.stop*y, length(r))
*(r::StepRange, y::Units) = StepRange(r.start*y, r.step*y, r.stop*y)
function /(x::Base.TwicePrecision, v::Quantity)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ end
@test r[3] === 0.3s
@test *(1:5, mm, s^-1) === 1mm*s^-1:1mm*s^-1:5mm*s^-1
@test *(1:5, mm, s^-1, mol^-1) === 1mm*s^-1*mol^-1:1mm*s^-1*mol^-1:5mm*s^-1*mol^-1
@test @inferred((0:2) * 3f0m) === StepRangeLen{typeof(0f0m)}(0.0m, 3.0m, 3) # issue #477
end
end
@testset "> Arrays" begin
Expand Down

0 comments on commit d67368a

Please sign in to comment.