ToInt32: (Signed 32 Bit Integer)

The abstract operation ToInt32 converts its argument to one of 232 integer values in the range −231 through231−1, inclusive. This abstract operation functions as follows:

  1. Let number be the result of calling ToNumber on the input argument.

  2. If number is NaN, +0, −0, +∞, or −∞, return +0.

  3. Let posInt be sign(number) * floor(abs(number)).

  4. Let int32bit be posInt modulo 232;

    that is, a finite integer value k of Number type with positive sign and less than 232 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 232.

  5. If int32bit is greater than or equal to 231, return int32bit − 232, otherwise return int32bit.


    sign , floor , abs , modulo 用法参见-> 这里

翻译成中文 !!!

抽象方法ToInt32将传入的参数转换成(-2^31,2^31-1]中的一个值。这个抽象方法的执行过程如下:

1.将传入参数进行ToNumber转换,设结果为number

2.如果number是NaN, +0, −0, +∞, or −∞ 直接返回0

3.设posInt 为sign(number) *floor(abs(number))  

4.设int32bit为posIntmodulo 2^32的值

5.如果int32bit大于等于2^31,返回int32bit − 2^32, 否则返回 int32bit