Javascript数字中的位数 [英] Number of bits in Javascript numbers
问题描述
我只在Javascript中使用整数(主要是添加数字并移动它们)。我不知道他们有多大可以不丢失任何一点。
I work in Javascript with integer numbers only (mainly adding numbers and shifting them). I wonder how big they can be without loosing any bits.
例如, X
的大小可以是 1<< X
将代表 2 ^ X
?
For example, how big X
can be such that 1 << X
will represent 2^X
?
推荐答案
JavaScript中的所有数字实际上都是符合IEEE-754标准的浮点数双精度数。它们具有53位尾数,这意味着任何大小约为9千万亿或更小的整数值 - 更具体地说,9,007,199,254,740,991 - 将被准确表示。
All numbers in JavaScript are actually IEEE-754 compliant floating-point doubles. These have a 53-bit mantissa which should mean that any integer value with a magnitude of approximately 9 quadrillion or less -- more specifically, 9,007,199,254,740,991 -- will be represented accurately.
注意:在2018年,主浏览器和NodeJS也在使用新的Javascript原始类型, BigInt ,用整数值幅度解决问题。
NOTICE: in 2018 main browsers and NodeJS are working also with the new Javascript's primitive-type, BigInt, solving the problems with integer value magnitude.
这篇关于Javascript数字中的位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!