Anim8or Community
General Category => Ongoing Anim8or Development => Topic started by: Steve on March 05, 2014, 05:26:09 pm
-
Build 1071 adds the integer bit-wise operators &, ^, |, << and >>. Since there is no unsigned int in ASL the right shift always sign extends.
Build 1075 adds bit negate ~, and ++ and --.
Note: Build 175 had a bug parsing prefix ++ and -- so it was replaced by build 1076.
-
Hey Steve,
Finally able to give these operators a shot (trying to implement this algorithm (http://devmaster.net/posts/6145/advanced-rasterization)), but couldn't help but notice that the bit-wise NOT (~) operator is missing. Granted, it can be done manually (http://stackoverflow.com/questions/1449260/bitwise-operations-without-bitwise-operators), but it'd be awesome if it were in there.
Thanks
-
Raxx
Until it's implemented,you could also apply XOR ^ between your integer and one which is all 1s to get the equivalent of a twiddle.
Hope it helps.
Claude
-
Hey Claude, makes perfect sense, totally ignored the XOR operator there.
I came up with this solution via code, but I'm wondering if there's a less intensive method of determining the all 1-bit integer. [edit]Scratch that
-
How about something like this:
return $int ^ 0xffffffff;
Haven't tested it,but It should work.
-
Hum...it works, apparently as it should. I think I'm just a little confuzzled about the bitwise NOT operation overall. Time to read up on it!
Thanks Claude, simplifies things tremendously.
-
Sorry,didn't have much time when I posted.
In case this 0xffffffff is the confusing part,I should explain.
In ASL, an int is a 32-bit signed integer. Constants may be hexadecimal.
So,we define our constant as 0xffffffff
0x indicates that the following characters are hexadecimal.
Each character represents 4 bits(4 zeros or ones).
Example:
0x0 0 0 0 0 f c 6
0000 0000 0000 0000 0000 1111 1100 0110
Read the first 2 paragraphs and look at the table lower on the right
side.
http://en.wikipedia.org/wiki/Hexadecimal
So, 0xffffffff gives us a 32 bits of 1.
If you already knew,it's OK.It might help someone else
interrested in ASL.
-
Hey Claude, nice explanation. I pretty much knew that part (a good refresher though ;)), but like you said it could help someone else.
My main confusion was, I thought NOT was supposed to flip just the numbered bits, not the entire 32-bit span.
For example, my assumption was:
Int: 244 (0xf4)
Normal: [0000 0000 0000 0000 0000 0000] 1111 0100
Assumed NOT: [0000 0000 0000 0000 0000 0000] 0000 1011
Actual NOT: [1111 1111 1111 1111 1111 1111] 0000 1011 (int value: -245)
-
I understand.
In C and C++,the bitwise complement operator flips every bit.
Since ASL most of the time follows the same rules,
we may assume that it will be like that.
The XOR operation is used as a sort of selective
complement operator.
Bitwise operators are not something I've used very often.Feels like a refresher course to me too.
Bye
Claude
-
I forgot about ~. I'll add it.
(I guess I should look at the C++ spec occasionally instead of trying to remember everything myself - getting too old for that!)
-
Bumping topic so it's apparent that I updated it.
-
I tested --/++ a bit, looking good. There is an issue with the C-like for loop though, incrementing/decrementing (like in the code below) doesn't work.
#command("object");
int $i;
file $c;
$c.open("$console", "w");
for ($i = 10; $i > 0; $i--)
{
$c.print("%d\n", $i);
}
$c.close();
I notice that these are only post-decrement/increment operators, not pre-decrement/increment. I rarely use pre-, so I don't really care, but figured it's worth pointing out.
By the way, having alt toggle arc rotate is like a sweet breath of fresh air :) Many thanks!
-
Hmmm. Pre increment and decrement should be there as well. I only have a couple of test cases (test cases are as much work as the original code !!!) so can you send me yours that don't work correctly?
-
Here's a few.
#command("object");
int $i;
file $c;
$i = 2;
$c.open("$console", "w");
$c.print("%d\n", $i);
$c.print("%d\n", (++$i)); // Fine in parenthesis
$c.print("%d\n", ++$i); // Causes Loading Error
$c.print("%d\n", --$i); // Causes Loading Error
++$i; // Causes Loading Error
--$i; // Causes Loading Error
$c.close();
-
Ahhh, foiled by the old Leading Unary Operator trick!
All my tests are of the form "$x = ++$y" so I can see the value of the expression as well as the underlying variable. Anim8or doesn't currently (and apparently never did!) accept expression statements that begin with any unary operator, such as:
-$i;
I'll fix this and have an update shortly.
-
I've posted build 1076 which should fix this problem as well as a slew of other corner cases such as:
$i + $j;
which is a valid C statement, however meaningless.