Reputation: 709
I tried to google it, but all key words references to funtions or solutions working with content of variable.
My question is simple. If variable represents a number,
var a = 1;
what is its max bit length? I mean, what highest number can it contain before buffer overflow happens? Is it int32? Is it int64? Is it a different length?
Thanks in advance
Upvotes: 0
Views: 106
Reputation: 172438
Numbers in Javascript are IEEE 754 floating point double-precision values which has a 53-bit mantissa. See the MDN:
Integer range for Number
The following example shows minimum and maximum integer values that can be represented as Number object (for details, refer to ECMAScript standard, chapter 8.5 The Number Type):
var biggestInt = 9007199254740992; var smallestInt = -9007199254740992;
Upvotes: 2
Reputation: 1074276
As the spec says, numbers in JavaScript are IEEE-754 double-precision floating point:
-1.7976931348623157e+308
through 1.7976931348623157e+308
(that latter is available via Number.MAX_VALUE
), which is to say the positive and negative versions of (2 - 2^-52) × 2^1023
, but they can't perfectly represent all of those values. Famously, 0.1 + 0.2
comes out as 0.30000000000000004
; see Is floating-point math broken?Number.MAX_SAFE_INTEGER
on ES2015-compliant JavaScript engines.MIN_SAFE_INTEGER
is -9,007,199,254,740,991Upvotes: 4