Number.MAX_SAFE_INTEGER
상수는 JavaScript에서 안전한 최대 정수값을 나타냅니다. (253 - 1
).
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Property attributes of Number.MAX_SAFE_INTEGER |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | no |
설명
MAX_SAFE_INTEGER
상수는 9007199254740991
(9,007,199,254,740,991 또는 약 9000조)의 값을 갖고 있습니다. 이 값의 이유는 JavaScript가 IEEE 754에 기술된 배정밀도 부동소숫점 형식 숫자체계를 사용하기 때문으로, 이로 인해 -(253 - 1)
과 253 - 1
사이의 수만 안전하게 표현할 수 있습니다.
여기서의 안전함이란 정수를 정확하고 올바르게 비교할 수 있음을 의미합니다. 예를 들어 Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
는 참으로 평가되며 이는 수학적으로 올바르지 않습니다. 더 자세한 내용은 Number.isSafeInteger()
를 참고하세요.
MAX_SAFE_INTEGER
는 Number
의 정적 속성이기 때문에, 직접 생성한 Number
객체의 속성이 아니라 Number.MAX_SAFE_INTEGER
형식으로 사용해야 합니다.
예제
Number.MAX_SAFE_INTEGER // 9007199254740991 Number.MAX_SAFE_INTEGER * Number.EPSILON // 2 because in floating points, the value is actually the decimal trailing "1" // except for in subnormal precision cases such as zero
폴리필
if (!Number.MAX_SAFE_INTEGER) {
Number.MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; // 9007199254740991
}
명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.MAX_SAFE_INTEGER' in that specification. |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) The definition of 'Number.MAX_SAFE_INTEGER' in that specification. |
Draft |
브라우저 호환성
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MAX_SAFE_INTEGER | Chrome Full support 34 | Edge Full support 12 | Firefox Full support 31 | IE No support No | Opera Full support Yes | Safari Full support 9 | WebView Android Full support Yes | Chrome Android Full support 34 | Firefox Android Full support 31 | Opera Android Full support Yes | Safari iOS Full support 9 | Samsung Internet Android Full support Yes | nodejs Full support 0.12 |
Legend
- Full support
- Full support
- No support
- No support