smath 1.0.1 → 1.0.2
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/dist/Polate.js +1 -1
- package/dist/SMath.js +4 -1
- package/package.json +1 -1
- package/types/SMath.d.ts +11 -0
package/dist/Polate.js
CHANGED
package/dist/SMath.js
CHANGED
|
@@ -5,7 +5,7 @@ var SMath = (function () {
|
|
|
5
5
|
function SMath() {
|
|
6
6
|
}
|
|
7
7
|
SMath.isNumber = function (n) {
|
|
8
|
-
return typeof n === 'number';
|
|
8
|
+
return typeof n === 'number' && n !== Infinity && n !== -Infinity;
|
|
9
9
|
};
|
|
10
10
|
SMath.clamp = function (n, min, max) {
|
|
11
11
|
if (n < min) {
|
|
@@ -20,6 +20,9 @@ var SMath = (function () {
|
|
|
20
20
|
if (epsilon === void 0) { epsilon = 1e-6; }
|
|
21
21
|
return a - b < epsilon && b - a < epsilon;
|
|
22
22
|
};
|
|
23
|
+
SMath.round = function (n, d) {
|
|
24
|
+
return Math.round(n * Math.pow(10, d)) / (Math.pow(10, d));
|
|
25
|
+
};
|
|
23
26
|
return SMath;
|
|
24
27
|
}());
|
|
25
28
|
exports.SMath = SMath;
|
package/package.json
CHANGED
package/types/SMath.d.ts
CHANGED
|
@@ -39,4 +39,15 @@ export declare abstract class SMath {
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
static approx(a: number, b: number, epsilon?: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Round a number to any number of decimal places.
|
|
44
|
+
* @param n The number to round
|
|
45
|
+
* @param d The number of places on the right side of the decimal
|
|
46
|
+
* @returns The rounded number
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* const pi = SMath.round(3.1416, 2); // 3.14
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
static round(n: number, d: number): number;
|
|
42
53
|
}
|