es.math.imul.js 700 B

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