unaryMinus.js 478 B

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