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 CHANGED
@@ -6,7 +6,7 @@ var Polate = (function () {
6
6
  }
7
7
  Polate.normalize = function (n, min, max) {
8
8
  if (min === max) {
9
- return min;
9
+ return 0;
10
10
  }
11
11
  return (n - min) / (max - min);
12
12
  };
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smath",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Small math function library",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
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
  }