es.math.imul.js 654 B

12345678910111213141516171819202122
  1. var $ = require('../internals/export');
  2. var fails = require('../internals/fails');
  3. var nativeImul = Math.imul;
  4. var FORCED = fails(function () {
  5. return nativeImul(0xFFFFFFFF, 5) != -5 || nativeImul.length != 2;
  6. });
  7. // `Math.imul` method
  8. // https://tc39.github.io/ecma262/#sec-math.imul
  9. // some WebKit versions fails with big numbers, some has wrong arity
  10. $({ target: 'Math', stat: true, forced: FORCED }, {
  11. imul: function imul(x, y) {
  12. var UINT16 = 0xFFFF;
  13. var xn = +x;
  14. var yn = +y;
  15. var xl = UINT16 & xn;
  16. var yl = UINT16 & yn;
  17. return 0 | xl * yl + ((UINT16 & xn >>> 16) * yl + xl * (UINT16 & yn >>> 16) << 16 >>> 0);
  18. }
  19. });