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 badges3 Answers
Reset to default 3News 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 callingBigInt()
, for example123n
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
, but123n !== 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