sameValue.js 632 B

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