什么是JavaScript的最大整数值,一个号码可以去不失precision? [英] What is JavaScript's highest integer value that a Number can go to without losing precision?

查看:188
本文介绍了什么是JavaScript的最大整数值,一个号码可以去不失precision?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是由语言定义的?是否有一个定义的最大?它是在不同的浏览器有什么不同?

Is this defined by the language? Is there a defined maximum? Is it different in different browsers?

推荐答案

+/- 9007199254740991

ECMA 8.5节 - 数字

请注意,所有的正和负整数,其量值是不大于2 在数式(事实上,整数0具有两个重presentations 53功能重新presentable, + 0和-0)。

Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number type (indeed, the integer 0 has two representations, +0 and −0).

他们是64位浮点值,最大的精确积分值是2 53 -1,或 9007199254740991 。在ES6,这被定义为<一href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER\">Number.MAX_SAFE_INTEGER.

They are 64-bit floating point values, the largest exact integral value is 253-1, or 9007199254740991. In ES6, this is defined as Number.MAX_SAFE_INTEGER.

请注意,该位运算符和移位运算32位整数操作,所以在这种情况下,最大安全整数2 31 -1或2147483647

Note that the bitwise operators and shift operators operate on 32-bit ints, so in that case, the max safe integer is 231-1, or 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

这篇关于什么是JavaScript的最大整数值,一个号码可以去不失precision?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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