unaryMinus.js 391 B

1234567891011121314151617
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var isNaN = require('../../helpers/isNaN');
  4. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-unaryMinus
  5. module.exports = function NumberUnaryMinus(x) {
  6. if (typeof x !== 'number') {
  7. throw new $TypeError('Assertion failed: `x` argument must be a Number');
  8. }
  9. if (isNaN(x)) {
  10. return NaN;
  11. }
  12. return -x;
  13. };