signedRightShift.js 653 B

12345678910111213141516171819202122232425
  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 modulo = require('../modulo');
  7. var Type = require('../Type');
  8. // https://262.ecma-international.org/12.0/#sec-numeric-types-number-signedRightShift
  9. module.exports = function NumberSignedRightShift(x, y) {
  10. if (Type(x) !== 'Number' || Type(y) !== 'Number') {
  11. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  12. }
  13. var lnum = ToInt32(x);
  14. var rnum = ToUint32(y);
  15. var shiftCount = modulo(rnum, 32);
  16. return lnum >> shiftCount;
  17. };