smath 1.6.0 → 1.6.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/README.md +2 -2
- package/dist/bin.js +5 -0
- package/dist/index.js +30 -1
- package/package.json +8 -3
- package/types/index.d.ts +10 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-

|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
smath can be installed from the official [npm package repository](https://www.npmjs.com/package/smath). It is highly recommended to install the latest version, which is installed by default with the following command.
|
|
13
13
|
|
|
14
14
|
```shell
|
|
15
|
-
npm i smath@1.6.
|
|
15
|
+
npm i smath@1.6.2
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Bugs and Requests
|
package/dist/bin.js
CHANGED
|
@@ -26,6 +26,7 @@ if (func.includes('help')) {
|
|
|
26
26
|
console.log(' translate <n> <min1> <max1> <min2> <max2>');
|
|
27
27
|
console.log(' : Linearly interpolate `n` from `min1`, `max1` to `min2`, `max2`');
|
|
28
28
|
console.log(' factorial <n> : Compute `n!` (factorial)');
|
|
29
|
+
console.log(' factors <n> : List the prime factors of `n`');
|
|
29
30
|
console.log(' error <exp> <act> : Calculate the normaized percent error between `exp` and `act`');
|
|
30
31
|
console.log(' sum <c0> [c1] ... [cn] : Compute a total of `n` numbers');
|
|
31
32
|
console.log(' prod <c0> [c1] ... [cn] : Compute a product of `n` numbers');
|
|
@@ -70,6 +71,10 @@ switch (func) {
|
|
|
70
71
|
console.log(_1.SMath.factorial(nums[0]));
|
|
71
72
|
break;
|
|
72
73
|
}
|
|
74
|
+
case ('factors'): {
|
|
75
|
+
console.log(_1.SMath.factors(nums[0]));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
73
78
|
case ('error'): {
|
|
74
79
|
console.log(_1.SMath.error(nums[0], nums[1]));
|
|
75
80
|
break;
|
package/dist/index.js
CHANGED
|
@@ -156,6 +156,35 @@ var SMath = /** @class */ (function () {
|
|
|
156
156
|
return n * this.factorial(n - 1);
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Factorize `n` into its prime factors.
|
|
161
|
+
* @param n Any positive integer
|
|
162
|
+
* @returns The array of prime factors
|
|
163
|
+
* @example
|
|
164
|
+
* ```js
|
|
165
|
+
* const y = SMath.factors(12); // [ 2, 2, 3 ]
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
SMath.factors = function (n) {
|
|
169
|
+
if (n < 0 || (n | 0) !== n) {
|
|
170
|
+
throw new Error('Input must be a positive integer!');
|
|
171
|
+
}
|
|
172
|
+
if (n <= 3) {
|
|
173
|
+
return [n];
|
|
174
|
+
}
|
|
175
|
+
var f = [];
|
|
176
|
+
var i = 2;
|
|
177
|
+
while (n > 1 && i <= n) {
|
|
178
|
+
if ((n / i) === ((n / i) | 0)) {
|
|
179
|
+
n /= i;
|
|
180
|
+
f.push(i);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
i++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return f;
|
|
187
|
+
};
|
|
159
188
|
/**
|
|
160
189
|
* Calculate the relative normalized error or deviation from any
|
|
161
190
|
* value to an accepted value. An error of 0 indicates that the
|
|
@@ -222,7 +251,7 @@ var SMath = /** @class */ (function () {
|
|
|
222
251
|
* ```
|
|
223
252
|
*/
|
|
224
253
|
SMath.median = function (data) {
|
|
225
|
-
data.sort();
|
|
254
|
+
data.sort(function (a, b) { return a - b; });
|
|
226
255
|
if (data.length % 2) {
|
|
227
256
|
return data[(data.length - 1) / 2];
|
|
228
257
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smath",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Small math function library",
|
|
5
5
|
"homepage": "https://npm.nicfv.com/smath",
|
|
6
6
|
"bin": "dist/bin.js",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"avg",
|
|
29
29
|
"average",
|
|
30
30
|
"mean",
|
|
31
|
+
"calculus",
|
|
32
|
+
"statistics",
|
|
33
|
+
"numeric",
|
|
34
|
+
"numerical",
|
|
35
|
+
"analysis",
|
|
31
36
|
"interpolate",
|
|
32
37
|
"interpolation",
|
|
33
38
|
"extrapolate",
|
|
@@ -47,9 +52,9 @@
|
|
|
47
52
|
"repository": "github:nicfv/npm",
|
|
48
53
|
"license": "MIT",
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@types/node": "20.
|
|
55
|
+
"@types/node": "20.12.4",
|
|
51
56
|
"exray": "1.0.2",
|
|
52
57
|
"typedoc": "0.25.12",
|
|
53
|
-
"typescript": "5.4.
|
|
58
|
+
"typescript": "5.4.4"
|
|
54
59
|
}
|
|
55
60
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -110,6 +110,16 @@ export declare abstract class SMath {
|
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
112
|
static factorial(n: number): number;
|
|
113
|
+
/**
|
|
114
|
+
* Factorize `n` into its prime factors.
|
|
115
|
+
* @param n Any positive integer
|
|
116
|
+
* @returns The array of prime factors
|
|
117
|
+
* @example
|
|
118
|
+
* ```js
|
|
119
|
+
* const y = SMath.factors(12); // [ 2, 2, 3 ]
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
static factors(n: number): Array<number>;
|
|
113
123
|
/**
|
|
114
124
|
* Calculate the relative normalized error or deviation from any
|
|
115
125
|
* value to an accepted value. An error of 0 indicates that the
|