JavaScript类型数组:64位整数?

时间:2022-02-21 17:36:12

JavaScript typed arrays, implemented in Firefox 4 and Chrome 7, are a very efficient way of storing and working with binary data in JavaScript. However, the current implementations only provide integer views up to 32 bits per member, with Int32Array and Uint32Array. Are 64-bit integer views being planned for implementation? How can I implement 64-bit integer views? How much slower will they be?

在Firefox 4和Chrome 7中实现的JavaScript类型数组是在JavaScript中存储和处理二进制数据的一种非常有效的方式。但是,当前实现仅提供每个成员最多32位的整数视图,使用Int32Array和Uint32Array。是否计划实施64位整数视图?如何实现64位整数视图?它们会慢多少?

1 个解决方案

#1


16  

There's no practical way to implement an Int64Array, because all numbers in JavaScript are 64-bit floating point numbers, which only have 53 bits of precision. Like Simeon said in his comment, you could use a big integer library, but it would be much slower.

实现Int64Array没有实用的方法,因为JavaScript中的所有数字都是64位浮点数,只有53位的精度。就像Simeon在他的评论中所说,你可以使用一个大的整数库,但速度要慢得多。

If you really need an array of 64-bit integers, regardless of performance, the Google Closure library has a 64-bit Long class that I would imagine is faster than a more general big integer library. I've never used it though, and I don't know if you can separate it easily from the rest of the library.

如果你真的需要一个64位整数数组,无论性能如何,Google Closure库都有一个64位的Long类,我认为它比一般的大整数库更快。我从来没有使用它,我不知道你是否可以轻松地将它与库的其他部分分开。

#1


16  

There's no practical way to implement an Int64Array, because all numbers in JavaScript are 64-bit floating point numbers, which only have 53 bits of precision. Like Simeon said in his comment, you could use a big integer library, but it would be much slower.

实现Int64Array没有实用的方法,因为JavaScript中的所有数字都是64位浮点数,只有53位的精度。就像Simeon在他的评论中所说,你可以使用一个大的整数库,但速度要慢得多。

If you really need an array of 64-bit integers, regardless of performance, the Google Closure library has a 64-bit Long class that I would imagine is faster than a more general big integer library. I've never used it though, and I don't know if you can separate it easily from the rest of the library.

如果你真的需要一个64位整数数组,无论性能如何,Google Closure库都有一个64位的Long类,我认为它比一般的大整数库更快。我从来没有使用它,我不知道你是否可以轻松地将它与库的其他部分分开。