divide.js 638 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var isFinite = require('../../helpers/isFinite');
  5. var isNaN = require('../../helpers/isNaN');
  6. var Type = require('../Type');
  7. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-divide
  8. module.exports = function NumberDivide(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. if (isNaN(x) || isNaN(y) || (!isFinite(x) && !isFinite(y))) {
  13. return NaN;
  14. }
  15. // shortcut for the actual spec mechanics
  16. return x / y;
  17. };