sameValueZero.js 497 B

1234567891011121314151617181920
  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-sameValueZero
  5. module.exports = function NumberSameValueZero(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. var xNaN = isNaN(x);
  10. var yNaN = isNaN(y);
  11. if (xNaN || yNaN) {
  12. return xNaN === yNaN;
  13. }
  14. return x === y;
  15. };