nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.44k stars 1.47k forks source link

Cardinality of sets prints unexpected value #3135

Closed gradha closed 9 years ago

gradha commented 9 years ago

With the following example:

type
  SquareIndex* = range[0..63]
  Bitboard* = set[SquareIndex]

proc test() =
  const values = [3, 47, 48, 54, 53, 63]
  var b: Bitboard
  for f in values:
    echo "Card: ", b.card
    b.incl(f)
    echo "Added ", f

  for f in 0..high(SquareIndex):
    if f in b:
      echo "Value ", f, " found in bitboard"

when isMainModule: test()

Compiled with Nim 0.11.2 under OSX shows the following output:

Card: 0
Added 3
Card: 1
Added 47
Card: 2
Added 48
Card: 2
Added 54
Card: 2
Added 53
Card: 2
Added 63
Value 3 found in bitboard
Value 47 found in bitboard
Value 48 found in bitboard
Value 53 found in bitboard
Value 54 found in bitboard
Value 63 found in bitboard

The cardinality doesn't increase for set values greater than 47. The expected result was to have a final cardinality of six.

Araq commented 9 years ago

Pretty sure this works on devel.