es6.math.imul.js 534 B

1234567891011121314151617
  1. // 20.2.2.18 Math.imul(x, y)
  2. var $export = require('./$.export')
  3. , $imul = Math.imul;
  4. // some WebKit versions fails with big numbers, some has wrong arity
  5. $export($export.S + $export.F * require('./$.fails')(function(){
  6. return $imul(0xffffffff, 5) != -5 || $imul.length != 2;
  7. }), 'Math', {
  8. imul: function imul(x, y){
  9. var UINT16 = 0xffff
  10. , xn = +x
  11. , yn = +y
  12. , xl = UINT16 & xn
  13. , yl = UINT16 & yn;
  14. return 0 | xl * yl + ((UINT16 & xn >>> 16) * yl + xl * (UINT16 & yn >>> 16) << 16 >>> 0);
  15. }
  16. });