简体   繁体   English

如何在 Node.js 中进行 64 位整数运算?

[英]How to do 64bit Integer arithmetic in Node.js?

Anyone have any suggestions on how to perform arithmetic on 64bit integers in Node.js?有人对如何在 Node.js 中对 64 位整数执行算术有任何建议吗? The node-int64 package doesn't seem to support that. node-int64 包似乎不支持。

Javascript does not support 64 bit integers, because the native number type is a 64-bit double, giving only 53 bits of integer range. Javascript 不支持 64 位整数,因为本机数字类型是 64 位双精度型,仅给出 53 位整数范围。

You can create arrays of 32-bit numbers (ie Uint32Array ) but if there were a 64-bit version of those there'd be no way to copy values from it into standalone variables.您可以创建 32 位数字的数组(即Uint32Array ),但如果有 64 位版本的数组,则无法将其中的值复制到独立变量中。

There are some modules around to provide 64bit integer support:有一些模块可以提供 64 位整数支持:

Maybe your problem can be solved using one of those libraries.也许您的问题可以使用这些库之一来解决。

As of v10.4.0 NodeJS supports the BigInt type natively (see MDN BigInt docs ).从 v10.4.0 开始,NodeJS 原生支持 BigInt 类型(参见MDN BigInt 文档)。 These support arithmetic operations too.这些也支持算术运算。

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

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