signedRightShift.js 536 B

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