ActionScript 3.0 整数溢出?

发布于 2024-11-06 17:55:16 字数 707 浏览 0 评论 0原文

我有一个旧的 AIR 文件,可以正常工作。我尝试重新编译它,但生成的航空文件有错误。

在深入研究代码后,我发现在某些地方字符串被解析为整数,并且生成的整数与字符串不对应。 所以我制作了一个简单的 Actionscript 文件并执行了代码:

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

并且变量将具有值

-584131582

所以这看起来像是溢出。但令我惊讶的是,我拥有的空气文件(我自己没有编译)运行得很好。所以我想知道 - int 的内部表示是否在某种程度上取决于用于编译的 Flex 或 AIR sdk 库的版本?

//编辑:看来它可以归结为这个测试:

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

然而,这对我来说是评估的

test1=false;
test2=true;

- 这个旧的 AIR 文件似乎将这两种情况评估为 true。怎么可能呢?

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

test1=false;
test2=true;

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欲拥i 2024-11-13 17:55:16

发生这种情况是因为 Give 数量超过了 ActionsScript Int 限制

int 数据类型在内部存储为 32 位整数,包含从 -2,147,483,648 (-231) 到2,147,483,647 (231 - 1),

和数字 3,710,835,714 超出它 1563352067

但你的解析结果显示编译器正在将其视为 Uint,其最大限制为 4,294,967,295

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

您应该使用 UintNumber 对于大整数/整数

此博客可能会帮助您
ActionScript 3 长整数值的数字数据类型问题

希望有效

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文