main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
800 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
[79a0317] | 4 | var isFinite = require('math-intrinsics/isFinite');
|
---|
| 5 | var isNaN = require('math-intrinsics/isNaN');
|
---|
[d565449] | 6 |
|
---|
| 7 | // https://262.ecma-international.org/12.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 (!isFinite(x)) {
|
---|
| 19 | return x;
|
---|
| 20 | }
|
---|
| 21 | if (!isFinite(y)) {
|
---|
| 22 | return y;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | if (x === y && x === 0) { // both zeroes
|
---|
| 26 | return Infinity / x === -Infinity && Infinity / y === -Infinity ? -0 : +0;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | // shortcut for the actual spec mechanics
|
---|
| 30 | return x + y;
|
---|
| 31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.