Skip to content

reverse of an unsigned range does not work as expected #29576

@simonschoelly

Description

@simonschoelly

If you reverse a range of unsigned integers, then you get an empty range:

julia> reverse(Int8(1):Int8(5)) |> collect
5-element Array{Int8,1}:
 5
 4
 3
 2
 1

julia> reverse(UInt8(1):UInt8(5)) |> collect
0-element Array{UInt8,1}

Maybe this is intentional but it is not what one (I) would expect.
The problem seems to be that by reversing we get a StepRange

julia> reverse(UInt8(1):UInt8(5))
0x05:0xff:0x04

and apparently there is a check for an overflow here, so the values never get wrapped around through 2-complement.

versioninfo:

julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = gvim

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions