Skip to content

Commit

Permalink
Fix #7420 – indexing a FloatRange with an OrdinalRange.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jun 28, 2014
1 parent c8adc94 commit e928eda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ function getindex(r::StepRange, s::Range{Int})
end

function getindex(r::FloatRange, s::OrdinalRange)
0 < last(s) <= length(r) || throw(BoundsError())
FloatRange(r[first(s)],step(r)*step(s),length(s),r.divisor)
isempty(s) || 1 <= first(s) <= length(r) &&
1 <= last(s) <= length(r) || throw(BoundsError())
FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor)
end

function show(io::IO, r::Range)
Expand Down
11 changes: 10 additions & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,16 @@ for T = (Float32, Float64,),# BigFloat),
start = convert(T,a)/den
step = convert(T,s)/den
stop = convert(T,(a+(n-1)*s))/den
@test [start:step:stop] == T[a:s:a+(n-1)*s]./den
r = start:step:stop
@test [r] == T[a:s:a+(n-1)*s]./den
# issue #7420
n = length(r)
@test [r[1:n]] == [r]
@test [r[2:n]] == [r][2:end]
@test [r[1:3:n]] == [r][1:3:n]
@test [r[2:2:n]] == [r][2:2:n]
@test [r[n:-1:2]] == [r][n:-1:2]
@test [r[n:-2:1]] == [r][n:-2:1]
end

# near-equal ranges
Expand Down

0 comments on commit e928eda

Please sign in to comment.