equal.js 479 B

123456789101112131415161718
  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-equal
  5. module.exports = function NumberEqual(x, y) {
  6. if (typeof x !== 'number' || typeof y !== 'number') {
  7. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  8. }
  9. if (isNaN(x) || isNaN(y)) {
  10. return false;
  11. }
  12. // shortcut for the actual spec mechanics
  13. return x === y;
  14. };