BigInt(9223372036854775807) //9223372036854775808n
I dont often work with large numbers so forgive me if this is a dumb question, but why is this not 9223372036854775807n?
Im expecting BigInt(9223372036854775807) //9223372036854775807n
BigInt(9223372036854775807) //9223372036854775808n
I dont often work with large numbers so forgive me if this is a dumb question, but why is this not 9223372036854775807n?
Im expecting BigInt(9223372036854775807) //9223372036854775807n
3
Answers
In javascript the BigInt is defined as 64 bit data type, which ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. So when you’re trying to operate on 9223372036854775807, it exceeds the limits and hence displays unexpected behaviour.
You can refer to https://www.tutorialspoint.com/what-is-javascript-s-highest-integer-value-that-a-number-can-go-to-without-losing-precision for better understanding.
If you want a
BigInt
with a value of9223372036854775807
, you should explicitly specify then
suffix to indicate that it’s aBigInt
:9223372036854775807 is Number,It’s already inaccurate.