| Issue 118: | logical shift doesn't clear sign bit | |
| 1 person starred this issue and may be notified of changes. | Back to list |
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
Jul 7, 2011
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
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... |