unsignedRightShift.js 618 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var ToInt32 = require('../ToInt32');
  5. var ToUint32 = require('../ToUint32');
  6. var Type = require('../Type');
  7. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-unsignedRightShift
  8. module.exports = function NumberUnsignedRightShift(x, y) {
  9. if (Type(x) !== 'Number' || Type(y) !== 'Number') {
  10. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  11. }
  12. var lnum = ToInt32(x);
  13. var rnum = ToUint32(y);
  14. var shiftCount = rnum & 0x1F;
  15. return lnum >>> shiftCount;
  16. };