Add integers, wrapping at 2^32. This uses 16-bit operations internally to work around bugs in some JS interpreters. - Node.js Number

Node.js examples for Number:Int

Description

Add integers, wrapping at 2^32. This uses 16-bit operations internally to work around bugs in some JS interpreters.

Demo Code


function safe_add(x, y) {
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

Related Tutorials