简体   繁体   English

JavaScript 是否具有双浮点数精度?

[英]Does JavaScript have double floating point number precision?

I know it's an odd question, but does JavaScript have the capacity to work with double's as opposed to single floats?我知道这是一个奇怪的问题,但是 JavaScript 是否有能力使用双精度而不是单浮点数? (64 bit floats vs. 32 bits.) (64 位浮点数与 32 位。)

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, 2 64 −2 53 +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)

In javascript type number it's float 64-bit number that support IEEE 754 standard and it's like double in 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 compatibility table.但请注意,它在 IE9 中不受支持,这里是浏览器兼容性表。

If you want extended presicion like long double , you can use double.js or decimal.js library.如果你想要像long double这样的扩展精度,你可以使用double.jsdecimal.js库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM