main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
882 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var isNaN = require('../../helpers/isNaN');
|
---|
| 6 |
|
---|
| 7 | // https://262.ecma-international.org/11.0/#sec-numeric-types-number-add
|
---|
| 8 |
|
---|
| 9 | module.exports = function NumberAdd(x, y) {
|
---|
| 10 | if (typeof x !== 'number' || typeof y !== 'number') {
|
---|
| 11 | throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | if (isNaN(x) || isNaN(y) || (x === Infinity && y === -Infinity) || (x === -Infinity && y === Infinity)) {
|
---|
| 15 | return NaN;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | if ((x === Infinity && y === Infinity) || (x === -Infinity && y === -Infinity)) {
|
---|
| 19 | return x;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | if (x === Infinity) {
|
---|
| 23 | return x;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | if (y === Infinity) {
|
---|
| 27 | return y;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | if (x === y && x === 0) {
|
---|
| 31 | return Infinity / x === -Infinity && Infinity / y === -Infinity ? -0 : +0;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if (x === -y || -x === y) {
|
---|
| 35 | return +0;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // shortcut for the actual spec mechanics
|
---|
| 39 | return x + y;
|
---|
| 40 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.