sameValue.js 556 B

12345678910111213141516171819
  1. 'use strict';
  2. var isNegativeZero = require('is-negative-zero');
  3. var $TypeError = require('es-errors/type');
  4. var NumberSameValueZero = require('./sameValueZero');
  5. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-sameValue
  6. module.exports = function NumberSameValue(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 (x === 0 && y === 0) {
  11. return !(isNegativeZero(x) ^ isNegativeZero(y));
  12. }
  13. return NumberSameValueZero(x, y);
  14. };