Skip to content

Commit

Permalink
tidy error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Feb 12, 2024
1 parent 2a156f1 commit ea12bdc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1602,26 +1602,26 @@ struct LogRange{T<:Real,X} <: AbstractArray{T,1}
stop::T
len::Int
extra::Tuple{X,X}
function LogRange{T}(start::T, stop::T, length::Int) where {T<:Real}
function LogRange{T}(start::T, stop::T, len::Int) where {T<:Real}
if T <: Integer
# LogRange{Int}(1, 512, 4) produces InexactError: Int64(7.999999999999998)
throw(ArgumentError("LogRange{T} does not support integer types"))
end
# LogRange(0, 1, 100) could be == [0,0,0,0,...,1], that's the limit start -> 0,
# but seems more likely to give silent surprises than returning NaN.
a = iszero(start) ? T(NaN) : T(start)
b = iszero(stop) ? T(NaN) : T(stop)
len = Int(length)
if len < 0
throw(ArgumentError(LazyString(
"LogRange(", start, ", ", stop, ", ", len, "): can't have negative length")))
elseif len == 1 && start != stop
throw(ArgumentError(LazyString(
"LogRange(", start, ", ", stop, ", ", len, "): endpoints differ, while length is 1")))
elseif start < 0 || stop < 0
# log would throw, but _log_twice64_unchecked does not
throw(DomainError((start, stop),
"LogRange(start, stop, length) does not accept negative numbers"))
end
if T <: Integer
# LogRange{Int}(1, 512, 4) produces InexactError: Int64(7.999999999999998)
throw(ArgumentError("LogRange{T} does not support integer types"))
end
ex = _logrange_extra(a, b, len)
new{T,typeof(ex[1])}(a, b, len, ex)
end
Expand Down

0 comments on commit ea12bdc

Please sign in to comment.