smath 1.5.0 → 1.5.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/README.md +2 -2
- package/dist/bin.js +18 -5
- package/dist/index.js +21 -5
- package/package.json +1 -1
- package/types/index.d.ts +17 -5
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.5.
|
|
15
|
+
npm i smath@1.5.1
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Bugs and Requests
|
package/dist/bin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var _a;
|
|
3
|
+
var _a, _b;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
var _1 = require(".");
|
|
6
|
-
var func = process.argv[2].toLowerCase(), nums = process.argv.slice(3).map(function (arg, i) {
|
|
6
|
+
var func = ((_a = process.argv[2]) !== null && _a !== void 0 ? _a : '').toLowerCase(), nums = process.argv.slice(3).map(function (arg, i) {
|
|
7
7
|
var num = Number.parseFloat(arg);
|
|
8
8
|
if (Number.isFinite(num)) {
|
|
9
9
|
return num;
|
|
@@ -22,13 +22,14 @@ if (func.includes('help')) {
|
|
|
22
22
|
console.log(' avg <c0> [c1] ... [cn] : Take an average of `n` numbers');
|
|
23
23
|
console.log(' varp <c0> [c1] ... [cn] : Compute the population variance of `n` numbers');
|
|
24
24
|
console.log(' vars <c0> [c1] ... [cn] : Compute the sample variance of `n` numbers');
|
|
25
|
+
console.log(' stdevp <c0> [c1] ... [cn]: Compute the population standard deviation of `n` numbers');
|
|
26
|
+
console.log(' stdevs <c0> [c1] ... [cn]: Compute the sample standard deviation of `n` numbers');
|
|
25
27
|
console.log(' approx <a> <b> [eps] : Check if `a` and `b` are approximately equal');
|
|
26
28
|
console.log(' clamp <n> <min> <max> : Clamp `n` between `min` and `max`');
|
|
27
29
|
console.log(' expand <n> <min> <max> : Expand normalized `n` between `min` and `max`');
|
|
28
30
|
console.log(' linspace <min> <max> <n> : Generate `n` linearly spaced numbers between `min` and `max`');
|
|
29
31
|
console.log(' logspace <min> <max> <n> : Generate `n` logarithmically spaced numbers between `min` and `max`');
|
|
30
|
-
console.log(' normalize <n> <min> <max
|
|
31
|
-
console.log(' : Normalize `n` between `min` and `max`');
|
|
32
|
+
console.log(' normalize <n> <min> <max>: Normalize `n` between `min` and `max`');
|
|
32
33
|
console.log(' translate <n> <min1> <max1> <min2> <max2>');
|
|
33
34
|
console.log(' : Linearly interpolate `n` from `min1`, `max1` to `min2`, `max2`');
|
|
34
35
|
console.log(' factorial <n> : Compute `n!` (factorial)');
|
|
@@ -56,8 +57,16 @@ switch (func) {
|
|
|
56
57
|
console.log(_1.SMath.vars(nums));
|
|
57
58
|
break;
|
|
58
59
|
}
|
|
60
|
+
case ('stdevp'): {
|
|
61
|
+
console.log(_1.SMath.stdevp(nums));
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case ('stdevs'): {
|
|
65
|
+
console.log(_1.SMath.stdevs(nums));
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
59
68
|
case ('approx'): {
|
|
60
|
-
console.log(_1.SMath.approx(nums[0], nums[1], (
|
|
69
|
+
console.log(_1.SMath.approx(nums[0], nums[1], (_b = nums[2]) !== null && _b !== void 0 ? _b : 1e-6));
|
|
61
70
|
break;
|
|
62
71
|
}
|
|
63
72
|
case ('clamp'): {
|
|
@@ -92,6 +101,10 @@ switch (func) {
|
|
|
92
101
|
console.log(_1.SMath.error(nums[0], nums[1]));
|
|
93
102
|
break;
|
|
94
103
|
}
|
|
104
|
+
case (''): {
|
|
105
|
+
console.error('Missing argument. Use with "help" for a list of commands.');
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
95
108
|
default: {
|
|
96
109
|
console.error('Unknown argument "' + func + '". Use with "help" for a list of commands.');
|
|
97
110
|
process.exit(1);
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var SMath = /** @class */ (function () {
|
|
|
17
17
|
/**
|
|
18
18
|
* Add up all the inputs.
|
|
19
19
|
* If none are present, returns 0.
|
|
20
|
-
* @param n
|
|
20
|
+
* @param n An array of numeric inputs
|
|
21
21
|
* @returns The sum total
|
|
22
22
|
* @example
|
|
23
23
|
* ```js
|
|
@@ -30,7 +30,7 @@ var SMath = /** @class */ (function () {
|
|
|
30
30
|
/**
|
|
31
31
|
* Multiply all the inputs.
|
|
32
32
|
* If none are present, returns 1.
|
|
33
|
-
* @param n
|
|
33
|
+
* @param n An array of numeric inputs
|
|
34
34
|
* @returns The product
|
|
35
35
|
* @example
|
|
36
36
|
* ```js
|
|
@@ -42,7 +42,7 @@ var SMath = /** @class */ (function () {
|
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Compute the average, or mean, of a set of numbers.
|
|
45
|
-
* @param n
|
|
45
|
+
* @param n An array of numeric inputs
|
|
46
46
|
* @returns The average, or mean
|
|
47
47
|
* @example
|
|
48
48
|
* ```js
|
|
@@ -54,7 +54,7 @@ var SMath = /** @class */ (function () {
|
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* Compute the variance of a **complete population**.
|
|
57
|
-
* @param n
|
|
57
|
+
* @param n An array of numeric inputs
|
|
58
58
|
* @returns The population variance
|
|
59
59
|
* @example
|
|
60
60
|
* ```js
|
|
@@ -67,7 +67,7 @@ var SMath = /** @class */ (function () {
|
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
69
69
|
* Compute the variance of a **sample**.
|
|
70
|
-
* @param n
|
|
70
|
+
* @param n An array of numeric inputs
|
|
71
71
|
* @returns The sample variance
|
|
72
72
|
* @example
|
|
73
73
|
* ```js
|
|
@@ -78,6 +78,22 @@ var SMath = /** @class */ (function () {
|
|
|
78
78
|
var mean = this.avg(n), squares = n.map(function (x) { return Math.pow((x - mean), 2); });
|
|
79
79
|
return this.sum(squares) / (n.length - 1);
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Compute the standard deviation of a **complete population**.
|
|
83
|
+
* @param n An array of numeric inputs
|
|
84
|
+
* @returns The population standard deviation
|
|
85
|
+
*/
|
|
86
|
+
SMath.stdevp = function (n) {
|
|
87
|
+
return Math.sqrt(this.varp(n));
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Compute the standard deviation of a **sample**.
|
|
91
|
+
* @param n An array of numeric inputs
|
|
92
|
+
* @returns The sample standard deviation
|
|
93
|
+
*/
|
|
94
|
+
SMath.stdevs = function (n) {
|
|
95
|
+
return Math.sqrt(this.vars(n));
|
|
96
|
+
};
|
|
81
97
|
/**
|
|
82
98
|
* Check if two numbers are approximately equal with a maximum abolute error.
|
|
83
99
|
* @param a Any number
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare abstract class SMath {
|
|
|
12
12
|
/**
|
|
13
13
|
* Add up all the inputs.
|
|
14
14
|
* If none are present, returns 0.
|
|
15
|
-
* @param n
|
|
15
|
+
* @param n An array of numeric inputs
|
|
16
16
|
* @returns The sum total
|
|
17
17
|
* @example
|
|
18
18
|
* ```js
|
|
@@ -23,7 +23,7 @@ export declare abstract class SMath {
|
|
|
23
23
|
/**
|
|
24
24
|
* Multiply all the inputs.
|
|
25
25
|
* If none are present, returns 1.
|
|
26
|
-
* @param n
|
|
26
|
+
* @param n An array of numeric inputs
|
|
27
27
|
* @returns The product
|
|
28
28
|
* @example
|
|
29
29
|
* ```js
|
|
@@ -33,7 +33,7 @@ export declare abstract class SMath {
|
|
|
33
33
|
static prod(n: Array<number>): number;
|
|
34
34
|
/**
|
|
35
35
|
* Compute the average, or mean, of a set of numbers.
|
|
36
|
-
* @param n
|
|
36
|
+
* @param n An array of numeric inputs
|
|
37
37
|
* @returns The average, or mean
|
|
38
38
|
* @example
|
|
39
39
|
* ```js
|
|
@@ -43,7 +43,7 @@ export declare abstract class SMath {
|
|
|
43
43
|
static avg(n: Array<number>): number;
|
|
44
44
|
/**
|
|
45
45
|
* Compute the variance of a **complete population**.
|
|
46
|
-
* @param n
|
|
46
|
+
* @param n An array of numeric inputs
|
|
47
47
|
* @returns The population variance
|
|
48
48
|
* @example
|
|
49
49
|
* ```js
|
|
@@ -53,7 +53,7 @@ export declare abstract class SMath {
|
|
|
53
53
|
static varp(n: Array<number>): number;
|
|
54
54
|
/**
|
|
55
55
|
* Compute the variance of a **sample**.
|
|
56
|
-
* @param n
|
|
56
|
+
* @param n An array of numeric inputs
|
|
57
57
|
* @returns The sample variance
|
|
58
58
|
* @example
|
|
59
59
|
* ```js
|
|
@@ -61,6 +61,18 @@ export declare abstract class SMath {
|
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
63
|
static vars(n: Array<number>): number;
|
|
64
|
+
/**
|
|
65
|
+
* Compute the standard deviation of a **complete population**.
|
|
66
|
+
* @param n An array of numeric inputs
|
|
67
|
+
* @returns The population standard deviation
|
|
68
|
+
*/
|
|
69
|
+
static stdevp(n: Array<number>): number;
|
|
70
|
+
/**
|
|
71
|
+
* Compute the standard deviation of a **sample**.
|
|
72
|
+
* @param n An array of numeric inputs
|
|
73
|
+
* @returns The sample standard deviation
|
|
74
|
+
*/
|
|
75
|
+
static stdevs(n: Array<number>): number;
|
|
64
76
|
/**
|
|
65
77
|
* Check if two numbers are approximately equal with a maximum abolute error.
|
|
66
78
|
* @param a Any number
|