Skip to content
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

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

Closed
simonschoelly opened this issue Oct 9, 2018 · 1 comment · Fixed by #29842
Closed

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

simonschoelly opened this issue Oct 9, 2018 · 1 comment · Fixed by #29842
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@simonschoelly
Copy link

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

@StefanKarpinski
Copy link
Member

Hah, nice bug.

@StefanKarpinski StefanKarpinski added the bug Indicates an unexpected problem or unintended behavior label Oct 9, 2018
mbauman added a commit that referenced this issue Oct 29, 2018
mbauman added a commit that referenced this issue Oct 29, 2018
vtjnash added a commit that referenced this issue Nov 11, 2021
vtjnash added a commit that referenced this issue Nov 12, 2021
Fixes #29576

Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
oscardssmith pushed a commit that referenced this issue Jan 6, 2022
Fixes #29576
Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
Fixes JuliaLang#29576
Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
Fixes JuliaLang#29576
Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants