Urara-Blog/node_modules/.pnpm-store/v3/files/42/0caeec509997cc653a3273e790947dc9d89a7d72d99e37c82e1305f74907329ec3f31b404bcd20de0f626c27ef0fc45498dfd9b7bbe91b36b6dc03a1e07a54
2022-08-14 01:14:53 +08:00

44 lines
960 B
Text

'use strict';
var GetIntrinsic = require('get-intrinsic');
var $TypeError = GetIntrinsic('%TypeError%');
var isNaN = require('../../helpers/isNaN');
var Type = require('../Type');
// https://262.ecma-international.org/11.0/#sec-numeric-types-number-add
module.exports = function NumberAdd(x, y) {
if (Type(x) !== 'Number' || Type(y) !== 'Number') {
throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
}
if (isNaN(x) || isNaN(y) || (x === Infinity && y === -Infinity) || (x === -Infinity && y === Infinity)) {
return NaN;
}
if ((x === Infinity && y === Infinity) || (x === -Infinity && y === -Infinity)) {
return x;
}
if (x === Infinity) {
return x;
}
if (y === Infinity) {
return y;
}
if (x === y && x === 0) {
return Infinity / x === -Infinity && Infinity / y === -Infinity ? -0 : +0;
}
if (x === -y || -x === y) {
return +0;
}
// shortcut for the actual spec mechanics
return x + y;
};