@shgysk8zer0/polyfills 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/all.min.js +13 -13
- package/all.min.js.map +1 -1
- package/array.js +323 -234
- package/math.js +61 -56
- package/package.json +1 -1
package/math.js
CHANGED
|
@@ -1,69 +1,74 @@
|
|
|
1
|
-
(
|
|
2
|
-
|
|
1
|
+
if (! Number.hasOwnProperty('isSafeInteger')) {
|
|
2
|
+
Number.MAX_SAFE_INTEGER = 2**53 -1;
|
|
3
|
+
Number.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;
|
|
4
|
+
Number.isSafeInteger = num => num <= Number.MAX_SAFE_INTEGER && num >= Number.MIN_SAFE_INTEGER;
|
|
5
|
+
}
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Number.isSafeInteger = num => num <= Number.MAX_SAFE_INTEGER && num >= Number.MIN_SAFE_INTEGER;
|
|
8
|
-
}
|
|
7
|
+
if (! Number.hasOwnProperty('EPSILON')) {
|
|
8
|
+
Number.EPSILON = 2**-52;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (! Math.hasOwnProperty('sign')) {
|
|
12
|
+
Math.sign = x => ((x > 0) - (x < 0)) || +x;
|
|
13
|
+
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (! Math.hasOwnProperty('trunc')) {
|
|
16
|
+
Math.trunc = x => {
|
|
17
|
+
const n = x - x%1;
|
|
18
|
+
return n===0 && (x<0 || (x===0 && (1/x !== 1/0))) ? -0 : n;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return n===0 && (x<0 || (x===0 && (1/x !== 1/0))) ? -0 : n;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
22
|
+
if (! Math.hasOwnProperty('expm1')) {
|
|
23
|
+
Math.expm1 = x => Math.exp(x) - 1;
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (! Math.hasOwnProperty('hypot')) {
|
|
27
|
+
Math.hypot = (...nums) => Math.sqrt(nums.reduce((sum, num) => sum + num**2, 0));
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if (! Math.hasOwnProperty('cbrt')) {
|
|
31
|
+
Math.cbrt = x => x**(1/3);
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (! Math.hasOwnProperty('log10')) {
|
|
35
|
+
Math.log10 = x => Math.log(x) * Math.LOG10E;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (! Math.hasOwnProperty('log2')) {
|
|
39
|
+
Math.log2 = x => Math.log(x) * Math.LOG2E;
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (! Math.hasOwnProperty('log1p')) {
|
|
43
|
+
Math.log1p = x => Math.log(1 + x);
|
|
44
|
+
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
if (! Math.hasOwnProperty('fround')) {
|
|
47
|
+
Math.fround = (function (array) {
|
|
48
|
+
return function(x) {
|
|
49
|
+
return array[0] = x, array[0];
|
|
50
|
+
};
|
|
51
|
+
})(new Float32Array(1));
|
|
52
|
+
}
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})(new Float32Array(1));
|
|
55
|
-
}
|
|
54
|
+
if (! (Math.clamp instanceof Function)) {
|
|
55
|
+
Math.clamp = function(value, min, max) {
|
|
56
|
+
return Math.min(Math.max(value, min), max);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
/*
|
|
61
|
+
* Question of if it will be `Math.clamp` or `Math.constrain`
|
|
62
|
+
*/
|
|
63
|
+
if (! (Math.constrain instanceof Function)) {
|
|
64
|
+
Math.constrain = Math.clamp;
|
|
65
|
+
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
67
|
+
/**
|
|
68
|
+
* @see https://github.com/tc39/proposal-math-sum
|
|
69
|
+
*/
|
|
70
|
+
if(! (Math.sum instanceof Function)) {
|
|
71
|
+
Math.sum = function(...nums) {
|
|
72
|
+
return nums.map(num => parseFloat(num)).reduce((sum, num) => sum + num);
|
|
73
|
+
};
|
|
74
|
+
}
|