Nick
Nick

Reputation: 4112

Do Javascript Numbers get represented as 64bit numbers in a 32bit browser?

I'm a bit confused about the size of a javascript number in a 32bit browser. Is it still represented as a 64bit number with max value at 2^53?

Upvotes: 4

Views: 2327

Answers (3)

Esailija
Esailija

Reputation: 140234

Answers couldn't be more wrong, it does depend on engine.

In V8 (Google Chrome, Opera, Node.js) 32-bit:

Integers that fit 31-bit signed representation (from -1073741824 to 1073741823) are represented directly by embedding it them in pointers.

Any other number is generally represented as a heap object that has a 64-bit double as a field for the numeric value (think of Java Double wrapper). In optimized functions such numbers can be temporarily stored directly on the stack and registers. Also certain kind of arrays can store doubles directly "permanently".

In V8 64-bit:

Same as 32-bit except integers can now fit in 32-bit signed representation (from -2147483648 to 2147483647) instead of 31-bit.

Upvotes: 8

Guffa
Guffa

Reputation: 700910

Yes. A number in Javascript is a double precision floating point number. It's the same regardless of the platform that it runs on.

Upvotes: 5

Nick
Nick

Reputation: 4112

I suppose my answer lies on MDN @ 64-bit integers

Upvotes: 0

Related Questions