Permalink
July 27, 2021 16:54
Newer
100644
33 lines (25 sloc)
848 Bytes
Ignoring revisions in .git-blame-ignore-revs.
1
'use strict';
2
3
var GetIntrinsic = require('get-intrinsic');
4
5
var $TypeError = GetIntrinsic('%TypeError%');
6
7
var isNaN = require('../../helpers/isNaN');
8
9
var Type = require('../Type');
10
11
// https://262.ecma-international.org/11.0/#sec-numeric-types-number-multiply
12
13
module.exports = function NumberMultiply(x, y) {
14
if (Type(x) !== 'Number' || Type(y) !== 'Number') {
15
throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
16
}
17
18
if (isNaN(x) || isNaN(y) || (x === 0 && !isFinite(y)) || (!isFinite(x) && y === 0)) {
19
return NaN;
20
}
21
if (!isFinite(x) && !isFinite(y)) {
22
return x === y ? Infinity : -Infinity;
23
}
24
if (!isFinite(x) && y !== 0) {
25
return x > 0 ? Infinity : -Infinity;
26
}
27
if (!isFinite(y) && x !== 0) {
28
return y > 0 ? Infinity : -Infinity;
29
}
30
31
// shortcut for the actual spec mechanics
32
return x * y;
33
};