最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Performing 128 bit math in nodejs - Stack Overflow

programmeradmin5浏览0评论

We need a way to do 128 bit math in a Node.js program. It looks like I can link a C++ library to do this, but since this will be open source for many platforms I would first like to try something that would not introduce special platform builds.

I see that JavaScript only supports only up to 64-bits. However, I have also seen JavaScript emulate a CPU and run Linux, so I'm certain this is possible. I'm not certain yet, but we probably need only a few basic math functions.

Do you know of something that exists already (I have not found one)? What approach would you take?

We need a way to do 128 bit math in a Node.js program. It looks like I can link a C++ library to do this, but since this will be open source for many platforms I would first like to try something that would not introduce special platform builds.

I see that JavaScript only supports only up to 64-bits. However, I have also seen JavaScript emulate a CPU and run Linux, so I'm certain this is possible. I'm not certain yet, but we probably need only a few basic math functions.

Do you know of something that exists already (I have not found one)? What approach would you take?

Share Improve this question asked Apr 21, 2014 at 22:57 jcalfee314jcalfee314 4,8709 gold badges46 silver badges78 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

News from the year 2020:

Node.js (version 10.4.0+) supports BigInts, which are arbitrarily large integers.

  • They can be created by appending an n to a number, or by calling BigInt(), for example
    • 123n
    • BigInt(123)
  • Operators +, *, -, /, **, % work as with numbers
  • Operator / truncates the result to an integer
  • Operators <<, >>, <<< work as with numbers
  • Operator >>> does not work
  • 123n == 123, but 123n !== 123 (they are different types)

For more information see: MDN web docs BigInt

This may work for you:

npm install big.js

It claims to be a small, fast JavaScript library for arbitrary-precision decimal arithmetic.

Try this.

Try

npm install int

and see if that works for you -- it is supposedly handling arbitrary precision integer

documentation here; https://www.npmjs/package/int

There is list of similar packages if that specific package does not work for you; https://www.npmjs/browse/keyword/bignum

发布评论

评论列表(0)

  1. 暂无评论