1

The MDN Web Docs refers that the Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript which has value of 2^53 - 1.

my question: is Number.MAX_SAFE_INTEGER has also value of (2^53 - 1) in 32-bit computer?

and if yes it has the same value how can JavaScript store this number (2^53 - 1) in 32 bits?!

Amjed Omar
  • 853
  • 2
  • 14
  • 30
  • 1
    Yes. In multiple bytes, with multiple instructions – Jonas Wilms Aug 29 '21 at 16:23
  • 3
    Numbers, according to the language spec, are 64-bit double-precision floating point values. A conforming JavaScript implementation on a 32-bit CPU must deal with that somehow. How? That's up to the implementors. – Pointy Aug 29 '21 at 16:23
  • 1
    Also, why do you care? Are you encountering some specific problem? – Pointy Aug 29 '21 at 16:24
  • 2
    Computers have supported double precision floating point for decades, long before there were 64-bit processors. They just store them in two 32-bit words. – Barmar Aug 29 '21 at 16:25
  • 1
    This will help you https://superuser.com/questions/698312/if-32-bit-machines-can-only-handle-numbers-up-to-232-why-can-i-write-100000000 – BadPiggie Aug 29 '21 at 16:27

1 Answers1

2

Yes. All JavaScript Numbers are represented using IEEE 754 binary64 (A.K.A. double precision floating point). This format takes 64 bits of space, but most modern 32-bit processors support it natively, and even if they didn't, it would be possible to implement floating point operations in software.

The "32-bit" in 32-bit processor refers to the word size.

D. Pardal
  • 6,173
  • 1
  • 17
  • 37