Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

JavaScript numbers can hold integers without losing precision up to Number.MAX_SAFE_INTEGER (9007199254740991, or 2⁵³-1), can be checked with Number.isSafeInteger(). Bitwise arithmetics, though, works on 32-bit numbers, so "casting" with | 0 will actually result in converting the number to 32-bit signed integer:

   2**53-1 | 0 = -1
   2**53-2 | 0 = -2
Which is modular arithmetic:

   (2**53-2) % 2**32 = 4294967294
   2**53-2 >>> 0 = 4294967294
          ( >>> 0 makes unsigned, 4294967294 | 0 = -2)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: