My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 118: logical shift doesn't clear sign bit
1 person starred this issue and may be notified of changes. Back to list
Status:  WontFix
Owner:  ----
Closed:  Jul 2011


 
Reported by michaelbaczynski@gmail.com, May 15, 2011
var x:Int = -1;
trace(x >>> 0); //-1, but should be 0xFFFFFFFF

I'm using this extensively in the js and flash target so it would be nice if cpp could provide the same behavior.
Jun 22, 2011
#1 michaelbaczynski@gmail.com
I realized that the cpp target doens't have unsigned integers so I guess it's better to use floats for representing integers > 0x7fffffff.
Jul 7, 2011
Project Member #2 gameh...@gmail.com
In c++, -1 (int) is the same bit pattern as 0xffffffff (unsigned int).  If you are doing logical operations ( |  & etc ) you can actually use the negative numbers.  You can even add then together and the patterns will hold.
What you can't to is the comparison operations and array indexes.
So if you are doing "flags" you can probably use them interchangeably. Even though it "traces" as -1, if it stored in memory as 0xffffffff.
However, if you are counting things, or doing coordinates, it is better as you say to use Floats.  I guess JS and flash "Number" is doing this conversion internally when it detects an overlow.
Using "unsigned" only help you in the 2billion-4billion range. Generally, your counting numbers would either be bigger or smaller than this range. 

Status: WontFix
Jul 7, 2011
#3 michaelbaczynski@gmail.com
I'm working on cross-platform random number generators, which usually produce unsigned integers, so I guess it's best to use Floats for all targets...


Powered by Google Project Hosting