+/- 9007199254740991
(+/- 9007199254740991)
ECMA Section 8.5 - Numbers
(ECMA第8.5节-数字)
Note that all the positive and negative integers whose magnitude is no greater than 2 53 are representable in the Number type (indeed, the integer 0 has two representations, +0 and ?0).
(请注意,所有大小不大于2 53的正整数和负整数都可以在Number类型中表示(实际上,整数0具有+0和-0两种表示形式)。)
They are 64-bit floating point values, the largest exact integral value is 2 53 -1, or 9007199254740991
.
(它们是64位浮点值,最大的精确整数值为2 53 -1或9007199254740991
。)
In ES6, this is defined as Number.MAX_SAFE_INTEGER .(在ES6中,将其定义为Number.MAX_SAFE_INTEGER 。)
Note that the bitwise operators and shift operators operate on 32-bit ints, so in that case, the max safe integer is 2 31 -1, or 2147483647.
(请注意,按位运算符和移位运算符对32位整数进行运算,因此在这种情况下,最大安全整数为2 31 -1或2147483647。)
Test it out!
(测试一下!)
var x = 9007199254740992; var y = -x; x == x + 1; // true ! y == y - 1; // also true ! // Arithmetic operators work, but bitwise/shifts only operate on int32: x / 2; // 4503599627370496 x >> 1; // 0 x | 1; // 1
Technical note on the subject of the number 9007199254740992: There is an exact IEEE-754 representation of this value, and you can assign and read this value from a variable, so for very carefully chosen applications in the domain of integers less than or equal to this value, you could treat this as a maximum value.
(关于编号为9007199254740992的主题的技术说明:该值有一个精确的IEEE-754表示形式,您可以从变量中分配和读取该值,因此对于在小于或等于整数的整数域中进行非常仔细选择的应用程序此值,您可以将其视为最大值。)
In the general case, you must treat this IEEE-754 value as inexact, because it is ambiguous whether it is encoding the logical value 9007199254740992 or 9007199254740993.
(在一般情况下,您必须将此IEEE-754值视为不精确,因为它是对逻辑值9007199254740992还是9007199254740993进行编码都是模棱两可的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…