Skip to content

Commit

Permalink
linspace: raise errors for cases that cannot be constructed.
Browse files Browse the repository at this point in the history
E.g. linspace(realmin(), realmax(), maxintfloat())
  • Loading branch information
StefanKarpinski committed Apr 13, 2015
1 parent f7bff89 commit 7ce35bf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@ function linspace{T<:FloatingPoint}(start::T, stop::T, len::T)
end
end
end
if isinf(n*start) || isinf(n*stop)
n, p = frexp(n)
a, c, s = start, stop, n
if isinf(a*n) || isinf(c*n)
s, p = frexp(s)
p = one(p) << p
start /= p; stop /= p
a /= p; c /= p
end
return LinSpace(start, stop, len, n)
if a*n/s == start && c*n/s == stop
return LinSpace(a, c, len, s)
end
error("linspace($start, $stop, $len): cannot be constructed")
end
function linspace{T<:FloatingPoint}(start::T, stop::T, len::Real)
T_len = convert(T, len)
Expand Down

0 comments on commit 7ce35bf

Please sign in to comment.