unaryMinus.js 511 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $BigInt = GetIntrinsic('%BigInt%', true);
  4. var $TypeError = GetIntrinsic('%TypeError%');
  5. var Type = require('../Type');
  6. var zero = $BigInt && $BigInt(0);
  7. // https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-unaryMinus
  8. module.exports = function BigIntUnaryMinus(x) {
  9. if (Type(x) !== 'BigInt') {
  10. throw new $TypeError('Assertion failed: `x` argument must be a BigInt');
  11. }
  12. if (x === zero) {
  13. return zero;
  14. }
  15. return -x;
  16. };