@@ -360,8 +360,8 @@ function steprange_last_empty(start::Integer, step, stop)
360
360
end
361
361
last
362
362
end
363
- # For types where x+oneunit(x) may not be well-defined
364
- steprange_last_empty (start, step, stop) = start - step
363
+ # For types where x+oneunit(x) may not be well-defined use the user-given value for stop
364
+ steprange_last_empty (start, step, stop) = stop
365
365
366
366
StepRange {T} (start, step:: S , stop) where {T,S} = StepRange {T,S} (start, step, stop)
367
367
StepRange (start:: T , step:: S , stop:: T ) where {T,S} = StepRange {T,S} (start, step, stop)
@@ -692,7 +692,7 @@ function checked_length(r::OrdinalRange{T}) where T
692
692
# s != 0, by construction, but avoids the division error later
693
693
start = first (r)
694
694
if s == zero (s) || isempty (r)
695
- return Integer (start - start + zero (s ))
695
+ return Integer (div ( start - start, oneunit (s) ))
696
696
end
697
697
stop = last (r)
698
698
if isless (s, zero (s))
@@ -719,7 +719,7 @@ function length(r::OrdinalRange{T}) where T
719
719
# s != 0, by construction, but avoids the division error later
720
720
start = first (r)
721
721
if s == zero (s) || isempty (r)
722
- return Integer (div (start- start, oneunit (s)))
722
+ return Integer (div (start - start, oneunit (s)))
723
723
end
724
724
stop = last (r)
725
725
if isless (s, zero (s))
@@ -811,7 +811,7 @@ first(r::OneTo{T}) where {T} = oneunit(T)
811
811
first (r:: StepRangeLen ) = unsafe_getindex (r, 1 )
812
812
first (r:: LinRange ) = r. start
813
813
814
- last (r:: OrdinalRange{T} ) where {T} = convert (T, r. stop)
814
+ last (r:: OrdinalRange{T} ) where {T} = convert (T, r. stop) # via steprange_last
815
815
last (r:: StepRangeLen ) = unsafe_getindex (r, length (r))
816
816
last (r:: LinRange ) = r. stop
817
817
0 commit comments