signedRightShift.js 576 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var ToInt32 = require('../ToInt32');
  4. var ToUint32 = require('../ToUint32');
  5. var modulo = require('../modulo');
  6. // https://262.ecma-international.org/12.0/#sec-numeric-types-number-signedRightShift
  7. module.exports = function NumberSignedRightShift(x, y) {
  8. if (typeof x !== 'number' || typeof y !== 'number') {
  9. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  10. }
  11. var lnum = ToInt32(x);
  12. var rnum = ToUint32(y);
  13. var shiftCount = modulo(rnum, 32);
  14. return lnum >> shiftCount;
  15. };