Skip to content

Commit

Permalink
Merge pull request #2959 from simonster/range-fix
Browse files Browse the repository at this point in the history
Fix float range behavior
  • Loading branch information
JeffBezanson committed Apr 28, 2013
2 parents c51a2dc + 30f8440 commit d121c4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function colon{T<:Real}(start::T, step::T, stop::T)
end
else
n = nf
len = iround(n)
len = itrunc(n)
end
if n >= typemax(Int)
error("Range: length ",n," is too large")
Expand All @@ -65,11 +65,17 @@ function colon{T<:Real}(start::T, stop::T)
if stop < start
len = 0
else
n = round(stop-start+1)
nf = stop - start + 1
if T <: FloatingPoint
n = round(nf)
len = abs(n-nf) < eps(n)*3 ? itrunc(n) : itrunc(nf)
else
n = nf
len = itrunc(n)
end
if n >= typemax(Int)
error("Range: length ",n," is too large")
end
len = itrunc(n)
end
Range1(start, len)
end
Expand Down
4 changes: 4 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,7 @@ i2619()
typealias Foo2919 Int
type Baz2919; Foo2919::Foo2919; end
@test Baz2919(3).Foo2919 === 3

# issue #2959
@test 1.0:1.5 == 1.0:1.0:1.5 == 1.0:1.0
@test 1.0:(.3-.1)/.1 == 1.0:2.0

0 comments on commit d121c4d

Please sign in to comment.