0

Whenever I write 23842899791470069 number into my browser's console it becomes 23842899791470068. Observed this in chrome and firefox. Can anyone confirm and explain the reason why is that so. Thanks in advance.

user3765023
  • 77
  • 10
  • Can confirm, can't explain. WEIRD ?! 23842899791470069 -> 23842899791470069 23842899791470070 -> 23842899791470070 23842899791470068 -> 23842899791470068 Why does only XX69 get decremented? – Isaac Abramowitz Jul 24 '18 at 14:58

1 Answers1

1

Javascript uses 64-bit doubles for number representation, which means that integers larger than 2^52 (4,503,599,627,370,496) can't be represented accurately (essentially they lose their least significant bits, though it seems to be a bit more complicated).

riv
  • 6,846
  • 2
  • 34
  • 63
  • But then why doesn't 23842899791470070 doesn't get decremented – Isaac Abramowitz Jul 24 '18 at 15:01
  • 1
    @isaac because it can be represented exactly. – Jonas Wilms Jul 24 '18 at 15:02
  • `essentially they lose their least significant bits` thats a bit missleading, its not that just some bits get shifted off at the end, its a bit more complicated – Jonas Wilms Jul 24 '18 at 15:04
  • Yea I'm not sure why it's reducing mantissa by 1. Normally (as observed in C++), ...70 should be rounded up to ...72, but the opposite is happening in JS. Must be something in the spec about it. – riv Jul 24 '18 at 15:13