divide.js 561 B

12345678910111213141516171819
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var isFinite = require('../../helpers/isFinite');
  4. var isNaN = require('../../helpers/isNaN');
  5. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-divide
  6. module.exports = function NumberDivide(x, y) {
  7. if (typeof x !== 'number' || typeof y !== 'number') {
  8. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  9. }
  10. if (isNaN(x) || isNaN(y) || (!isFinite(x) && !isFinite(y))) {
  11. return NaN;
  12. }
  13. // shortcut for the actual spec mechanics
  14. return x / y;
  15. };