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