bitwiseNOT.js 500 B

12345678910111213141516
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var ToInt32 = require('../ToInt32');
  4. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-bitwiseNOT
  5. module.exports = function NumberBitwiseNOT(x) {
  6. if (typeof x !== 'number') {
  7. throw new $TypeError('Assertion failed: `x` argument must be a Number');
  8. }
  9. var oldValue = ToInt32(x);
  10. // Return the result of applying the bitwise operator op to lnum and rnum. The result is a signed 32-bit integer.
  11. return ~oldValue;
  12. };