Can't apply units to a range
Closed this issue · 3 comments
I think this should work:
julia> (1:0.25:4)u"inch"
ERROR: Cannot create an additive identity from `Type{<:Quantity}`, as the dimensions are unknown. Please use `zero(::Quantity)` instead.
julia> collect(1:0.25:4)u"inch"
13-element Vector{Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}}:
0.025400000000000002 m
0.03175 m
0.0381 m
0.04445 m
...
Came up in JuliaLang/julia#56610, which is about 1u"inch":0.25u"inch":4u"inch"
. Constructing a range like that will (bugs aside) circumvent all the "do what I mean" floating-point magic of 0:0.1:1
. But making the range first & then applying units would mean the magic applies to the numbers as written.
So I guess we need a multiplication operator with StepRange
? Or should it be with AbstractRange
? I am surprised because AbstractRange{T} <: AbstractVector{T}
, and you can already multiply with vectors (as you see above).
There are special method for scalar * range, which try to produce more ranges, instead of the AbstractVector
path which makes a Vector
. One of these must call zero(T)
.
Got it, thanks. I put a fix in #158, want to take a look?