[CIQBUG] unary ! operator does bitwise inversion instead of a boolean inversion

I'm surprised that this has not been found sooner. The following code does not behave as expected...

for (var i = 0; i < 3; ++i) {
Sys.println(Lang.format("i=$1$ j=$2$ k=$3$", [ i, !i, !!i ]));
}


It results in the following output...

i=0 j=-1 k=0
i=1 j=-2 k=1
i=2 j=-3 k=2


In the C/C++ languages (where the return type of operator! called on an integer is of type integer) similar code would produce this...

$ cat t.c
#include <stdio.h>

int main()
{
for (int i = 0; i < 3; ++i) {
printf("i=%d j=%d k=%d", i, !i, !!i);
}
}

$ g++ t.c -o t && t
i=0 j=1 k=0
i=1 j=0 k=1
i=2 j=0 k=1


In javascript (where the result of the ! operator is of type boolean), it produces...

i=0, j=true, k=false
i=1, j=false, k=true
i=2, j=false, k=true


In python there is no logical ! operator, but there is the logical not operator which is the same. Python produces..

$ cat t.py

for i in range(0, 3):
print i, not i, not not i

$ python t.py
0 True False
1 False True
2 False True


Travis
  • Thanks for the report, Travis--I'll get this on the books to be investigated. By the way, you've reported a couple of other bugs in the past week or two that I have pending to investigate, but haven't yet gotten to. They haven't been forgotten!