shim.js 497 B

1234567891011121314151617
  1. /* eslint no-bitwise: "off" */
  2. // Thanks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
  3. // /Global_Objects/Math/imul
  4. "use strict";
  5. module.exports = function (val1, val2) {
  6. var xh = (val1 >>> 16) & 0xffff
  7. , xl = val1 & 0xffff
  8. , yh = (val2 >>> 16) & 0xffff
  9. , yl = val2 & 0xffff;
  10. // The shift by 0 fixes the sign on the high part
  11. // the final |0 converts the unsigned value into a signed value
  12. return (xl * yl + ((xh * yl + xl * yh) << 16 >>> 0)) | 0;
  13. };