0

Is the value of Number.MAX_VALUE a limitation only for numbers of data type Number? Doesn't BigInt have the same upper bound?

And another one question... Does BigInt represent number in 64-bit format IEEE-754? Since the BigInt format represents large numbers, can the BigInt value take up more space than 64 bits?

Ivan
  • 478
  • 2
  • 13
  • 1
    The first sentence on [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt): _"`BigInt` is a built-in object whose constructor returns a bigint primitive - also called a `BigInt` value, or sometimes just a `BigInt` - **to represent whole numbers larger than `2^53 - 1` (`Number.MAX_SAFE_INTEGER`), which is the largest number JavaScript can represent with a number primitive** (or Number value). BigInt values can be used **for arbitrarily large integers**."_ – Andreas Aug 12 '21 at 11:05
  • 1
    _"In JavaScript, [`BigInt`](https://developer.mozilla.org/en-US/docs/Glossary/BigInt) is a numeric data type that can represent integers in the [arbitrary precision format](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic)."_ – Andreas Aug 12 '21 at 11:07
  • 1
    There is no upper limit specified for BIgInt, for more detail refer https://stackoverflow.com/questions/53335545/whats-the-biggest-bigint-value-in-js-as-per-spec – Harsh Saini Aug 12 '21 at 11:09
  • @Andreas: MDN is being surprisingly inaccurate in its wording there: the "largest number JavaScript can represent with a number primitive" is `Number.MAX_VALUE`, which is about 2^1024. `MAX_SAFE_INTEGER` is the biggest _whole_ (or "integer") number that can still be incremented by `1` without losing precision. Number values between MAX_SAFE_INTEGER and MAX_VALUE will be rounded (to 53 significant bits). – jmrk Aug 12 '21 at 14:56

1 Answers1

3

Doesn't BigInt have the same upper bound?

No, BigInts have no specified limit. That said, realistically, there will always be implementation-defined limits (just like for Strings, Arrays, etc.). Currently, Chrome allows a billion bits, and Firefox allows a million bits. The expectation is that most realistically-occurring BigInts won't run into this limit.

Does BigInt represent number in 64-bit format IEEE-754?

No, IEEE-754 is a floating-point format, so it's not useful for BigInts, which have integer values. Besides, they have "unlimited" precision.

can the BigInt value take up more space than 64 bits?

Yes, BigInts can consume a lot more than 64 bits. For example, a BigInt with a thousand bits (such as 2n ** 999n) will need (about) a thousand bits of memory (likely rounded up to the next multiple of 4 or 8 bytes, plus a small object header, specifics depend on the engine).

jmrk
  • 34,271
  • 7
  • 59
  • 74