subtract.js 536 B

12345678910111213141516171819
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var Type = require('../Type');
  5. var NumberAdd = require('./add');
  6. var NumberUnaryMinus = require('./unaryMinus');
  7. // https://262.ecma-international.org/12.0/#sec-numeric-types-number-subtract
  8. module.exports = function NumberSubtract(x, y) {
  9. if (Type(x) !== 'Number' || Type(y) !== 'Number') {
  10. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  11. }
  12. return NumberAdd(x, NumberUnaryMinus(y));
  13. };