Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function length(r::OrdinalRange{T}) where T
# s != 0, by construction, but avoids the division error later
start = first(r)
if s == zero(s) || isempty(r)
return Integer(start - start + zero(s))
return Integer(div(start-start, oneunit(s)))
end
stop = last(r)
if isless(s, zero(s))
Expand Down
1 change: 1 addition & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ using .Main.Furlongs
@testset "dimensional correctness" begin
@test length(Vector(Furlong(2):Furlong(10))) == 9
@test length(range(Furlong(2), length=9)) == checked_length(range(Furlong(2), length=9)) == 9
@test @inferred(length(StepRange(Furlong(2), Furlong(1), Furlong(1)))) == 0
@test Vector(Furlong(2):Furlong(1):Furlong(10)) == Vector(range(Furlong(2), step=Furlong(1), length=9)) == Furlong.(2:10)
@test Vector(Furlong(1.0):Furlong(0.5):Furlong(10.0)) ==
Vector(Furlong(1):Furlong(0.5):Furlong(10)) == Furlong.(1:0.5:10)
Expand Down
2 changes: 1 addition & 1 deletion test/testhelpers/Furlongs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Furlong{p,T<:Number} <: Number
end
Furlong(x::T) where {T<:Number} = Furlong{1,T}(x)
Furlong(x::Furlong) = x
(::Type{T})(x::Furlong) where {T<:Number} = T(x.val)::T
(::Type{T})(x::Furlong{0}) where {T<:Number} = T(x.val)::T
Furlong{p}(v::Number) where {p} = Furlong{p,typeof(v)}(v)
Furlong{p}(x::Furlong{q}) where {p,q} = (@assert(p==q); Furlong{p,typeof(x.val)}(x.val))
Furlong{p,T}(x::Furlong{q}) where {T,p,q} = (@assert(p==q); Furlong{p,T}(T(x.val)))
Expand Down