julia
95a52a5d - An edge case for `length` (#31221)

Commit
6 years ago
An edge case for `length` (#31221) * An edge case for `length` Though `length` of `AbstractUnitRange` for `(U)Int` and `(U)Int64` has special cased with checked arithmetic, the `(U)Int128` dosen't and uses generic fallback. Therefore, it overflows for ```julia julia> r = typemin(Int128):typemax(Int128) -170141183460469231731687303715884105728:170141183460469231731687303715884105727 julia> length(r) 0 julia> r = typemin(UInt128):typemax(UInt128) 0x00000000000000000000000000000000:0xffffffffffffffffffffffffffffffff julia> length(r) 0x00000000000000000000000000000000 ``` whereas ```julia julia> r = typemin(Int64):typemax(Int64) -9223372036854775808:9223372036854775807 julia> length(r) ERROR: OverflowError: 9223372036854775807 -y overflowed for type Int64 Stacktrace: [1] throw_overflowerr_binaryop(::Symbol, ::Int64, ::Int64) at ./checked.jl:154 [2] checked_sub at ./checked.jl:223 [inlined] [3] length(::UnitRange{Int64}) at ./range.jl:540 [4] top-level scope at none:0 julia> r = typemin(UInt64):typemax(UInt64) 0x0000000000000000:0xffffffffffffffff julia> length(r) ERROR: OverflowError: 18446744073709551615 +y overflowed for type UInt64 Stacktrace: [1] throw_overflowerr_binaryop(::Symbol, ::UInt64, ::UInt64) at ./checked.jl:154 [2] checked_add at ./checked.jl:166 [inlined] [3] length(::UnitRange{UInt64}) at ./range.jl:544 [4] top-level scope at none:0 ``` I believe this is an inconsistency. * update StepRange also * Add `length` tests for edge cases * Add StepRange tests too
Author
Committer
Parents
Loading