问题
Consider the following code:
var combined:Number = Number(4294967296) | Number(2403025069);
var testLimit:Number = 6697992365;
trace("Combined is:", combined, "should be", testLimit);
Output is:
Combined is: -1891942227 should be 6697992365
Why?! I thought Number datatypes can hold 64 bit integers (okay- really 52-bit, but the numbers above are nowhere near that limit)
回答1:
From the documentation:
|bitwise OR OperatorConverts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits of either expression1 or expression2 are 1.
...
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
来源:https://stackoverflow.com/questions/21747341/binary-math-on-number-objects-limited-to-32-bits