Skip to content

Unsigned ranges with large ("negative") step are (semi)empty #29801

@PeterJacko

Description

@PeterJacko

While signed integers can count backwards,

julia> collect( Int16( 10 ) : -Int16( 1 ) : Int16( 0 ) )
11-element Array{Int16,1}:
 10
  9
  8
  7
  6
  5
  4
  3
  2
  1
  0

unsigned integers can't :(

julia> collect( UInt16( 10 ) : -UInt16( 1 ) : UInt16( 0 ) )
0-element Array{UInt16,1}

I am using it in a for loop like

for n = UInt16( 10 ) : -UInt16( 1 ) : UInt16( 0 )
    ...
end

because I need "n" to be of type UInt16 inside the loop (to avoid type changes, to improve performance).

julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\JuliaPro-1.0.1.1\app-1.29.0\atom.exe" -a
  JULIA_NUM_THREADS = 2
  JULIA_PKG_SERVER = https://pkg.juliacomputing.com/
  JULIA_PKG_TOKEN_PATH = C:\Users\Peter\.julia\token.toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    regressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions