JavaScript 是否具有双浮点数精度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3605925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does JavaScript have double floating point number precision?
提问by Travis
I know it's an odd question, but does JavaScript have the capacity to work with double's as opposed to single floats? (64 bit floats vs. 32 bits.)
我知道这是一个奇怪的问题,但是 JavaScript 是否有能力处理双精度而不是单浮点数?(64 位浮点数与 32 位。)
回答by Moin Zaman
All numbers in JavaScript are 64-bit floating point numbers.
JavaScript 中的所有数字都是 64 位浮点数。
Ref:
参考:
http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference
http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference
回答by Daniel Vandersluis
According to the ECMA-262 specification (ECMAScript is the specification for Javascript), section 8.5:
根据 ECMA-262 规范(ECMAScript 是 Javascript 的规范),第 8.5 节:
The Number type has exactly 18437736874454810627 (that is, 264?253+3) values, representing the double-precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic
Number 类型正好有 18437736874454810627(即 2 64?2 53+3)个值,表示 IEEE 二进制浮点运算标准中指定的双精度 64 位格式 IEEE 754 值
Source: http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf(PDF)
来源:http: //www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf(PDF)
回答by Pavel Melnikov
In javascript type numberit's float 64-bit number that support IEEE 754 standard and it's like doublein C. And you can create 32-bit typed arrays by commands below and control each byte in each component by binding corresponded buffer.
在javascript类型number中,它是支持IEEE 754标准的64位浮点数,就像C中的double一样。您可以通过下面的命令创建32位类型化数组,并通过绑定相应的缓冲区来控制每个组件中的每个字节。
let a = new Float32Array(length);
let b = new Float64Array(length);
But note that it's not supported in IE9, here browser compatibilitytable.
但请注意,它在 IE9 中不受支持,这里是浏览器兼容性表。
If you want extended presicion like long double, you can use double.jsor decimal.jslibrary.
如果你想要像long double这样的扩展精度,你可以使用double.js或 decimal.js库。

