Skip to content

Commit ea12bdc

Browse files
committed
tidy error handling
1 parent 2a156f1 commit ea12bdc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

base/range.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,26 +1602,26 @@ struct LogRange{T<:Real,X} <: AbstractArray{T,1}
16021602
stop::T
16031603
len::Int
16041604
extra::Tuple{X,X}
1605-
function LogRange{T}(start::T, stop::T, length::Int) where {T<:Real}
1605+
function LogRange{T}(start::T, stop::T, len::Int) where {T<:Real}
1606+
if T <: Integer
1607+
# LogRange{Int}(1, 512, 4) produces InexactError: Int64(7.999999999999998)
1608+
throw(ArgumentError("LogRange{T} does not support integer types"))
1609+
end
16061610
# LogRange(0, 1, 100) could be == [0,0,0,0,...,1], that's the limit start -> 0,
16071611
# but seems more likely to give silent surprises than returning NaN.
16081612
a = iszero(start) ? T(NaN) : T(start)
16091613
b = iszero(stop) ? T(NaN) : T(stop)
1610-
len = Int(length)
16111614
if len < 0
16121615
throw(ArgumentError(LazyString(
16131616
"LogRange(", start, ", ", stop, ", ", len, "): can't have negative length")))
16141617
elseif len == 1 && start != stop
16151618
throw(ArgumentError(LazyString(
16161619
"LogRange(", start, ", ", stop, ", ", len, "): endpoints differ, while length is 1")))
16171620
elseif start < 0 || stop < 0
1621+
# log would throw, but _log_twice64_unchecked does not
16181622
throw(DomainError((start, stop),
16191623
"LogRange(start, stop, length) does not accept negative numbers"))
16201624
end
1621-
if T <: Integer
1622-
# LogRange{Int}(1, 512, 4) produces InexactError: Int64(7.999999999999998)
1623-
throw(ArgumentError("LogRange{T} does not support integer types"))
1624-
end
16251625
ex = _logrange_extra(a, b, len)
16261626
new{T,typeof(ex[1])}(a, b, len, ex)
16271627
end

0 commit comments

Comments
 (0)