2

I've been looking at a lot of math in Javascript recently, and have seen lots of lines that end with "|0" at the end of a line. For instance, I was looking at the asm.js output of the Coinhive mining code, and see things like this all over the place:

k = (d[a + 45 >> 0] | 0) << 1;
l = c[4768 + (k << 2) >> 2] | 0;
k = c[4768 + ((k | 1) << 2) >> 2] | 0;
m = (d[a + 54 >> 0] | 0) << 1;

You can see that the various operations all end with "|0". These are operations on typed array values, so that may be why. It's just that I seem to vaguely recall seeing an explanation once before, but can't find any sort of answer at the moment.

Does anyone know why this needs to be done in Javascript?

superqd
  • 333
  • 4
  • 12
  • 4
    "forces" 32bit signed integer - see [Bitwise Operators DOCUMENTATION](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) – Jaromanda X Oct 23 '17 at 05:31
  • Ah. Thanks for the quick answer! – superqd Oct 23 '17 at 05:33
  • https://stackoverflow.com/questions/30156122/what-is-this-asm-style-x-0-some-javascript-programmers-are-now-using – melpomene Oct 23 '17 at 05:35
  • 4
    Possible duplicate of [What is this asm style "x | 0" some javascript programmers are now using?](https://stackoverflow.com/questions/30156122/what-is-this-asm-style-x-0-some-javascript-programmers-are-now-using) – aknosis Oct 23 '17 at 06:02

0 Answers0