开发者

ActionScript 3.0 integer overflow?

开发者 https://www.devze.com 2023-03-04 04:49 出处:网络
I have an old AIR file that works fine. I tried to recompile it but the resulting airfile is buggy. After digging in the code, i found that at some place strings are parsed to ints, and that the resu

I have an old AIR file that works fine. I tried to recompile it but the resulting airfile is buggy.

After digging in the code, i found that at some place strings are parsed to ints, and that the resulting int does not correspond to the string. So i made a simple Actionscript file and executed the code:

var test:int = parseInt("3710835714");

and the variable will have the value

-584131582

So this looks like an overflow. But i'm surprised that the air file i have (which i didn't compile myself) runs just fine. So I wonder - does the internal representation of int somehow depend on what version of the Flex or AIR sdk libraries one is using for compiling?

//edit: it seems it boils down to this test:

        var obj:Object = new Object();
        obj.val="3710835714";
        var test1:Boolean = (obj.val==-584131582);
        var test2:Boolean = (int(obj.val)==-584131582);

this evaluates for me to

tes开发者_如何学JAVAt1=false;
test2=true;

however - the this old AIR file seems to evaluate both cases to true. How can that be?


It is happening due to Give number exceeds ActionsScript Int limit

The int data type is stored internally as a 32-bit integer and comprises the set of integers from -2,147,483,648 (-231) to 2,147,483,647 (231 - 1),

and number 3,710,835,714 exceeds it by 1563352067

but your parse result shows compiler is considering it as Uint, whose Max limit is 4,294,967,295 i.e

-584131581 = 3,710,835,714 - 4,294,967,295

You should use Uint or Number for big whole-numbers/integers

this blog may helps you
ActionScript 3 Number data type problem with long integer values

Hopes that works

0

精彩评论

暂无评论...
验证码 换一张
取 消