-1

I have recently found the bignumber.js library:

source: https://github.com/MikeMcl/bignumber.js

What I'm not sure of is if there is a limit to how big the number operations can be? I have been looking into the documentation, trying to find sources online. But nothing as of yet.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Webeng
  • 7,050
  • 4
  • 31
  • 59
  • 2
    Why not ask on the repo? It's not uncommon to open an issue for clarification or just contact the maintainer directly. That said, (without actually looking) I'd guess it probably stores the numbers as strings giving you an absurdly large max value (for a given base, `b^maxint` I think). – CollinD Jul 07 '17 at 21:22

2 Answers2

2

I haven't worked with bignumber.js but a small peek into http://mikemcl.github.io/bignumber.js/#range has shown me that it seems to be configurable.

BigNumber.config({ RANGE: 500 })
BigNumber.config().RANGE     // [ -500, 500 ]
new BigNumber('9.999e499')   // '9.999e+499'
new BigNumber('1e500')       // 'Infinity'
new BigNumber('1e-499')      // '1e-499'
new BigNumber('1e-500')      // '0'
1

If you run this:

console.log(new BigNumber('123456789012345678901234567890').c);

You can see that numbers are stored as arrays, of maximum 14 digits

So the actual limitation would be the maximum length you can have for an array, multiplied by 14. This depends a lot on your machine, but assuming you have the best machine ever, ECMA-262 v6.0 says the limit is for the length of an array is 2^32-1, which is the size of ToUint32, so, theoretically, you could store a number with 14 * (2^32-1) digits using that library, that's something like:

console.log(new BigNumber(2).pow(32).sub(1).mul(14).toString());

Which is something around 60129542130 digits

Piyin
  • 1,823
  • 1
  • 16
  • 23