I'm using a server-side calculation which needs to generate (with *
and +
operations) and compare 40-bit integers. I'm aware that at that point the V8 engine stores the numbers as Double
rather than int
. Can I rely on these numbers to be generated and compared correctly?
My intuition says yes - doubles shouldn't have trouble with that - but I'm not sure how to check or where to find information on this.
Description. The MAX_SAFE_INTEGER constant has a value of 9007199254740991 (9,007,199,254,740,991, or ~9 quadrillion). Double precision floating point format only has 52 bits to represent the mantissa, so it can only safely represent integers between -(253 – 1) and 253 – 1.
Number type. The Number type is a double-precision 64-bit binary format IEEE 754 value.
JavaScript Number MAX_VALUE MAX_VALUE returns the largest number possible in JavaScript. Number. MAX_VALUE has the value of 1.7976931348623157e+308.
The BigInt. asUintN() method can be useful to stay in the range of 64-bit arithmetic.
A JavaScript Number
, which is a 64-bit IEEE 754 floating point value, can store integers from -253 to 253 without loss of precision, since doubles can store up to 53 bits of mantissa (52 explictly).
References:
ECMA-262: 4.3.19 Number value
Double-precision floating point numbers (Wikipedia)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With