Number.MAX_SAFE_INTEGER
Number.MAX_SAFE_INTEGER
静态数据属性表示 JavaScript 中的最大安全整数 (253 – 1)。
¥The Number.MAX_SAFE_INTEGER
static data property represents the maximum safe integer in JavaScript (253 – 1).
对于更大的整数,请考虑使用 BigInt
。
¥For larger integers, consider using BigInt
.
Try it
值
描述
¥Description
双精度浮点格式 只有 52 位来表示 mantissa,因此它只能安全地表示 -(253 – 1) 和 253 – 1 之间的整数。在这种情况下,"安全的" 指的是准确表示整数并正确比较它们的能力。例如,Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
将计算为 true,这在数学上是不正确的。请参阅 Number.isSafeInteger()
了解更多信息。
¥Double precision floating point format only has 52 bits to represent the mantissa, so it can only safely represent integers between -(253 – 1) and 253 – 1. "Safe" in this context refers to the ability to represent integers exactly and to compare them correctly. For example, Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
will evaluate to true, which is mathematically incorrect. See Number.isSafeInteger()
for more information.
由于 MAX_SAFE_INTEGER
是 Number
的静态属性,因此你始终将其用作 Number.MAX_SAFE_INTEGER
,而不是作为数字值的属性。
¥Because MAX_SAFE_INTEGER
is a static property of Number
, you always use it as Number.MAX_SAFE_INTEGER
, rather than as a property of a number value.
示例
MAX_SAFE_INTEGER 的返回值
MAX_SAFE_INTEGER 和 EPSILON 之间的关系
¥Relationship between MAX_SAFE_INTEGER and EPSILON
Number.EPSILON
为 2-52,而 MAX_SAFE_INTEGER
为 253 – 1 — 两者均源自尾数宽度,即 53 位(最高位始终为 是 1)。将它们相乘得到的值非常接近(但不等于)2。
¥Number.EPSILON
is 2-52, while MAX_SAFE_INTEGER
is 253 – 1 — both of them are derived from the width of the mantissa, which is 53 bits (with the highest bit always being 1). Multiplying them will give a value very close — but not equal — to 2.
Number.MAX_SAFE_INTEGER * Number.EPSILON; // 1.9999999999999998
规范
Specification |
---|
ECMAScript Language Specification # sec-number.max_safe_integer |
浏览器兼容性
BCD tables only load in the browser