在ActionScript 3,为什么是大的int值数量的动态类型? [英] In Actionscript 3, why is the dynamic type of large int values Number?

查看:170
本文介绍了在ActionScript 3,为什么是大的int值数量的动态类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,如果我创建一个较大的值的int,对象的动态类型似乎是数量。

I have noticed that if I create an int with a large value, the dynamic type of the object seems to be Number.

例如:

var int1:int = 0x8000000;
var type1:String = flash.utils.getQualifiedClassName(int1); // Returns "int"

var int2:int = 0x10000000;
var type2:String = flash.utils.getQualifiedClassName(int2); // Returns "Number"

这是怎么回事呢?这两个值都远低于一个int 的最大值,这是2,147,483,647(2 ^ 31-1)。

What is going on here? Both of the values are well below the maximum value of an int, which is 2,147,483,647 (2^31-1).

推荐答案

这是怎么回事的是,AS3虚拟机使用32位的原子来存储原始类型的值。

What's going on is that the AS3 virtual machine uses 32 bit "atoms" to store the values of primitive types.

3的那些32位被用于描述的类型,这意味着有29位左。

3 of those 32 bits are used for describing the type, meaning there are 29 bits left.

由于 INT 是一个符号类型 - 用1位的标志 - 留下的28位正整数。制作人数最多,你可以写在剩下的28位:

Since int is a signed type - using 1 bit for the sign - that leaves 28 bits for a positive integer. Making the highest number you can write in the remaining 28 bits:

0x0FFFFFFF = 268435455

只要整数需要超过29位时,原子是由虚拟机变成了一个键入(这实在是再psented为29 $ P $位指针到实际的64位双precision浮动)。

As soon as the integer needs more than 29 bits, the atom is changed by the VM into a Number type (which is really represented as a 29 bit pointer to the actual 64 bit double precision float).

所以,定义为一个int的最大价值的价值并没有真正全部多大意义(因为可以储存整数值高达53位,但 INT 将其限定为32) - 除在以下方面:

So, the value defined as "maximum value of an int" doesn't really make all that much sense (since Number can store integral values up to 53 bits, but int will limit it to 32) - other than in terms of:

  • 与其他语言/技术(其中大部分是用32位的整数)

  • communicating with other languages/technologies (which mostly use 32 bits for their integers)

做的结果(大部分)predictable以用于32位整数的程序员;以及

making the results (mostly) predictable to programmers used to 32 bit integers; and

面向未来的(如果在未来的内部重新presentation变化)。

future-proofing (in case the internal representation changes in the future).

作为一个旁注,也有相当多的特点与整数和数字 - 包括这样的:

As a sidenote, there are quite a few peculiarities with ints and Numbers - including that this:

var i:Number = 2.0;

...存储为INT,直到实际需要的小数。

... is stored as int until the decimals are actually needed.

这篇关于在ActionScript 3,为什么是大的int值数量的动态类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆