-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounds-checking failure while indexing an empty UnitRange
if there's an overflow
#45389
Comments
I don't think either of these are realistically fixable. The The indexing one is a result of the overflow that happened in julia> typemin(Int) + 1000 - 1
-9223372036854774809 |
|
If there's nothing that needs to change to the current overflow behavior, should we close this? |
One option is to change the indexing behavior to use _in_unit_range(v::UnitRange, val, i::Integer) = 0 < i <= v.stop - v.start + 1 but this will add an overhead to address somewhat uncommon use cases. |
This behavior is somewhat interesting julia> r = typemin(Int):typemax(Int)
-9223372036854775808:9223372036854775807
julia> length(r)
0
julia> isempty(r)
false Ideally this should be consistent, overflow or not |
What do you think
Personally, the behaviour of As a related issue, because an empty range is indicated by stop < start, if you start a range at the typemin then you get wacky behaviour if length is 0: # length == 0; !isempty
julia> range(typemin(Int); length=0)
-9223372036854775808:9223372036854775807
# Gets promoted to UnitRange{Int64} and is fine.
julia> range(typemin(Int8); length=0)
-128:-129
# But if we construct a UnitRange{Int8} then `range` is lying to us again:
# length == 256; !isempty
julia> range(typemin(Int8), length=zero(Int8)) |> length
256
# length and isempty are correct for this one, but you'll get an `InexactError` if you try to access the `last` value of the range
julia> range(typemin(UInt8), length=zero(UInt8)) |> length
0
# with a UInt range, the `last` value is wrong, but isempty and length are still correct.
julia> range(typemin(UInt); length=zero(UInt)) |> last
0xffffffffffffffff I think defining Here are some possible improvements:
|
Related:
The text was updated successfully, but these errors were encountered: