diff --git a/base/range.jl b/base/range.jl index 6979e3575ffa2..caac244b703b2 100644 --- a/base/range.jl +++ b/base/range.jl @@ -207,10 +207,10 @@ let smallint = (Int === Int64 ? function length{T <: smallint}(r::StepRange{T}) isempty(r) && return int(0) - div(int(r.stop+r.step - r.start), int(r.step)) + div(int(r.stop)+int(r.step) - int(r.start), int(r.step)) end - length{T <: smallint}(r::UnitRange{T}) = int(r.stop - r.start + 1) + length{T <: smallint}(r::UnitRange{T}) = int(r.stop) - int(r.start) + 1 end first{T}(r::OrdinalRange{T}) = oftype(T, r.start) diff --git a/test/ranges.jl b/test/ranges.jl index f0d5bc281b23d..b72f30c458497 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -363,3 +363,12 @@ for f in (mean, median) @test_approx_eq f(2:0.1:n) f([2:0.1:n]) end end + +# issue #8531 +let smallint = (Int === Int64 ? + (Int8,Uint8,Int16,Uint16,Int32,Uint32) : + (Int8,Uint8,Int16,Uint16)) + for T in smallint + @test length(typemin(T):typemax(T)) == 2^(8*sizeof(T)) + end +end