extra-math 1.5.1 → 1.6.0
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/LICENSE +1 -1
- package/README.md +66 -95
- package/deno.lock +42 -0
- package/index.d.ts +19 -342
- package/index.js +52 -498
- package/index.test.ts +105 -0
- package/package.json +12 -97
- package/index.mjs +0 -496
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,53 +1,27 @@
|
|
|
1
|
-
**Mathematics** is the classification and study of all possible patterns [(1)]
|
|
2
|
-
📦 [Node.js](https://www.npmjs.com/package/extra-math),
|
|
3
|
-
🌐 [Web](https://www.npmjs.com/package/extra-math.web),
|
|
4
|
-
📜 [Files](https://unpkg.com/extra-math/),
|
|
5
|
-
📰 [JSDoc](https://nodef.github.io/extra-math/),
|
|
6
|
-
📘 [Wiki](https://github.com/nodef/extra-math/wiki/).
|
|
7
|
-
|
|
8
|
-
This package includes common number functions related to querying *about*
|
|
9
|
-
numbers, *comparing* numbers, *rounding* numbers, performing *rounded division*,
|
|
10
|
-
performing *modulo* operations, *controlling range* of numbers, performing
|
|
11
|
-
*arithmetic* operations, obtaining *divisors* of a number (and related
|
|
12
|
-
operations), getting the number of possible *arrangements* of a set of objects,
|
|
13
|
-
performing *geometry*-related calculations, performing basic *statistical*
|
|
14
|
-
analysis, and finding various *statistical means*.
|
|
15
|
-
|
|
16
|
-
**Natural numbers**: There are 3 different ways of performing the *modulo*
|
|
17
|
-
operation: [rem], [mod], and [modp]. [gcd]/`HCF` and [lcm] of a list of numbers
|
|
18
|
-
can be obtained. To calculate the number of ways of *ordering items*, use
|
|
19
|
-
[factorial]/`P(n, k)`, [binomial]/`C(n, k)`, or [multinomial]/`n!/k₁!k₂!...`.
|
|
20
|
-
|
|
21
|
-
**Real numbers**: *Range* of a number can be controlled with [constrain],
|
|
22
|
-
[normalize], or [remap]. Use [lerp] for *linear interpolation* (or extrapolation);
|
|
23
|
-
[root] for calculating the *n-th root* of a number; and [log] to find the
|
|
24
|
-
*logarithm* of a number with a given base.
|
|
25
|
-
|
|
26
|
-
**Geometry**: Perform conversion from [degrees] to [radians] and vice versa.
|
|
27
|
-
Find the [magnitude] of a vector or [distance] between two points.
|
|
28
|
-
|
|
29
|
-
**Statistics**: For a list of numbers, we can calculate the [sum], [product],
|
|
30
|
-
[arithmeticMean]. [median] gives the value lying in the middle when the numbers are
|
|
31
|
-
sorted, and [modes] gives the values which are repeated most often. The
|
|
32
|
-
difference between the largest and the smallest values is the [range].
|
|
33
|
-
[variance] is a measure of variability of numbers.
|
|
34
|
-
|
|
35
|
-
This package is available in *Node.js* and *Web* formats. To use it on the web,
|
|
36
|
-
simply use the `extra_math` global variable after loading with a `<script>`
|
|
37
|
-
tag from the [jsDelivr CDN].
|
|
1
|
+
**Mathematics** is the classification and study of all possible patterns [(1)].
|
|
38
2
|
|
|
39
|
-
|
|
40
|
-
[
|
|
3
|
+
▌
|
|
4
|
+
📦 [JSR](https://jsr.io/@nodef/extra-math),
|
|
5
|
+
📦 [NPM](https://www.npmjs.com/package/extra-math),
|
|
6
|
+
📰 [Docs](https://jsr.io/@nodef/extra-math/doc).
|
|
7
|
+
|
|
8
|
+
This package includes common number functions related to querying *about* numbers, *comparing* numbers, *rounding* numbers, performing *rounded division*, performing *modulo* operations, *controlling range* of numbers, performing *arithmetic* operations, obtaining *divisors* of a number (and related operations), getting the number of possible *arrangements* of a set of objects, performing *geometry*-related calculations, performing basic *statistical* analysis, and finding various *statistical means*.
|
|
9
|
+
|
|
10
|
+
**Natural numbers**: There are 3 different ways of performing the *modulo* operation: [rem], [mod], and [modp]. [gcd]/`HCF` and [lcm] of a list of numbers can be obtained. To calculate the number of ways of *ordering items*, use [factorial]/`P(n, k)`, [binomial]/`C(n, k)`, or [multinomial]/`n!/k₁!k₂!...`.
|
|
11
|
+
|
|
12
|
+
**Real numbers**: *Range* of a number can be controlled with [constrain], [normalize], or [remap]. Use [lerp] for *linear interpolation* (or extrapolation); [root] for calculating the *n-th root* of a number; and [log] to find the *logarithm* of a number with a given base.
|
|
41
13
|
|
|
42
|
-
|
|
14
|
+
**Geometry**: Perform conversion from [degrees] to [radians] and vice versa. Find the [magnitude] of a vector or [distance] between two points.
|
|
15
|
+
|
|
16
|
+
**Statistics**: For a list of numbers, we can calculate the [sum], [product], [arithmeticMean]. [median] gives the value lying in the middle when the numbers are sorted, and [modes] gives the values which are repeated most often. The difference between the largest and the smallest values is the [range]. [variance] is a measure of variability of numbers.
|
|
17
|
+
|
|
18
|
+
[(1)]: https://en.wikipedia.org/wiki/Walter_Warwick_Sawyer
|
|
43
19
|
|
|
44
20
|
<br>
|
|
45
21
|
|
|
46
22
|
|
|
47
23
|
```javascript
|
|
48
|
-
|
|
49
|
-
// import * as xmath from "extra-math";
|
|
50
|
-
// import * as xmath from "https://unpkg.com/extra-math/index.mjs"; (deno)
|
|
24
|
+
import * as xmath from "jsr:@nodef/extra-math";
|
|
51
25
|
|
|
52
26
|
xmath.sum(1, 2, 3, 4);
|
|
53
27
|
// → 10
|
|
@@ -68,7 +42,7 @@ xmath.lcm(2, 3, 4);
|
|
|
68
42
|
|
|
69
43
|
## Index
|
|
70
44
|
|
|
71
|
-
|
|
|
45
|
+
| Name | Description |
|
|
72
46
|
| ---- | ---- |
|
|
73
47
|
| [floor] | Round down a number to specific precision. |
|
|
74
48
|
| [ceil] | Round up a number to specific precision. |
|
|
@@ -132,7 +106,7 @@ xmath.lcm(2, 3, 4);
|
|
|
132
106
|
|
|
133
107
|
## References
|
|
134
108
|
|
|
135
|
-
- [
|
|
109
|
+
- [An accurate approximation formula for gamma function; Yang, et al. (2018)](https://doi.org/10.1186/s13660-018-1646-6)
|
|
136
110
|
- [MathLib by @alawatthe](https://github.com/alawatthe/MathLib)
|
|
137
111
|
- [Processing Reference](https://processing.org/reference)
|
|
138
112
|
- [Common mathematical functions by cppreference](https://en.cppreference.com/w/cpp/numeric/math)
|
|
@@ -148,56 +122,53 @@ xmath.lcm(2, 3, 4);
|
|
|
148
122
|
<br>
|
|
149
123
|
|
|
150
124
|
|
|
151
|
-
[](https://wolfram77.github.io)<br>
|
|
152
126
|
[](https://nodef.github.io)
|
|
153
|
-
[](https://zenodo.org/badge/latestdoi/141781770)
|
|
154
|
-
[](https://coveralls.io/github/nodef/extra-math?branch=master)
|
|
155
|
-
[](https://codeclimate.com/github/nodef/extra-math/test_coverage)
|
|
156
|
-
[](https://codeclimate.com/github/nodef/extra-math/maintainability)
|
|
157
127
|

|
|
158
128
|
|
|
159
|
-
|
|
160
|
-
[
|
|
161
|
-
[
|
|
162
|
-
[
|
|
163
|
-
[
|
|
164
|
-
[
|
|
165
|
-
[
|
|
166
|
-
[
|
|
167
|
-
[
|
|
168
|
-
[
|
|
169
|
-
[
|
|
170
|
-
[
|
|
171
|
-
[
|
|
172
|
-
[
|
|
173
|
-
[
|
|
174
|
-
[
|
|
175
|
-
[
|
|
176
|
-
[
|
|
177
|
-
[
|
|
178
|
-
[
|
|
179
|
-
[
|
|
180
|
-
[
|
|
181
|
-
[
|
|
182
|
-
[
|
|
183
|
-
[
|
|
184
|
-
[
|
|
185
|
-
[
|
|
186
|
-
[
|
|
187
|
-
[
|
|
188
|
-
[
|
|
189
|
-
[
|
|
190
|
-
[
|
|
191
|
-
[
|
|
192
|
-
[
|
|
193
|
-
[
|
|
194
|
-
[
|
|
195
|
-
[
|
|
196
|
-
[
|
|
197
|
-
[
|
|
198
|
-
[
|
|
199
|
-
[
|
|
200
|
-
[
|
|
201
|
-
[
|
|
202
|
-
[
|
|
203
|
-
[
|
|
129
|
+
|
|
130
|
+
[floor]: https://jsr.io/@nodef/extra-math/doc/~/floor
|
|
131
|
+
[ceil]: https://jsr.io/@nodef/extra-math/doc/~/ceil
|
|
132
|
+
[round]: https://jsr.io/@nodef/extra-math/doc/~/round
|
|
133
|
+
[floorDiv]: https://jsr.io/@nodef/extra-math/doc/~/floorDiv
|
|
134
|
+
[ceilDiv]: https://jsr.io/@nodef/extra-math/doc/~/ceilDiv
|
|
135
|
+
[roundDiv]: https://jsr.io/@nodef/extra-math/doc/~/roundDiv
|
|
136
|
+
[rem]: https://jsr.io/@nodef/extra-math/doc/~/rem
|
|
137
|
+
[mod]: https://jsr.io/@nodef/extra-math/doc/~/mod
|
|
138
|
+
[modp]: https://jsr.io/@nodef/extra-math/doc/~/modp
|
|
139
|
+
[constrain]: https://jsr.io/@nodef/extra-math/doc/~/constrain
|
|
140
|
+
[normalize]: https://jsr.io/@nodef/extra-math/doc/~/normalize
|
|
141
|
+
[remap]: https://jsr.io/@nodef/extra-math/doc/~/remap
|
|
142
|
+
[lerp]: https://jsr.io/@nodef/extra-math/doc/~/lerp
|
|
143
|
+
[isPow]: https://jsr.io/@nodef/extra-math/doc/~/isPow
|
|
144
|
+
[prevPow]: https://jsr.io/@nodef/extra-math/doc/~/prevPow
|
|
145
|
+
[nextPow]: https://jsr.io/@nodef/extra-math/doc/~/nextPow
|
|
146
|
+
[root]: https://jsr.io/@nodef/extra-math/doc/~/root
|
|
147
|
+
[log]: https://jsr.io/@nodef/extra-math/doc/~/log
|
|
148
|
+
[properDivisors]: https://jsr.io/@nodef/extra-math/doc/~/properDivisors
|
|
149
|
+
[aliquotSum]: https://jsr.io/@nodef/extra-math/doc/~/aliquotSum
|
|
150
|
+
[minPrimeFactor]: https://jsr.io/@nodef/extra-math/doc/~/minPrimeFactor
|
|
151
|
+
[maxPrimeFactor]: https://jsr.io/@nodef/extra-math/doc/~/maxPrimeFactor
|
|
152
|
+
[primeFactors]: https://jsr.io/@nodef/extra-math/doc/~/primeFactors
|
|
153
|
+
[primeExponentials]: https://jsr.io/@nodef/extra-math/doc/~/primeExponentials
|
|
154
|
+
[isPrime]: https://jsr.io/@nodef/extra-math/doc/~/isPrime
|
|
155
|
+
[gcd]: https://jsr.io/@nodef/extra-math/doc/~/gcd
|
|
156
|
+
[lcm]: https://jsr.io/@nodef/extra-math/doc/~/lcm
|
|
157
|
+
[factorial]: https://jsr.io/@nodef/extra-math/doc/~/factorial
|
|
158
|
+
[binomial]: https://jsr.io/@nodef/extra-math/doc/~/binomial
|
|
159
|
+
[multinomial]: https://jsr.io/@nodef/extra-math/doc/~/multinomial
|
|
160
|
+
[degrees]: https://jsr.io/@nodef/extra-math/doc/~/degrees
|
|
161
|
+
[radians]: https://jsr.io/@nodef/extra-math/doc/~/radians
|
|
162
|
+
[magnitude]: https://jsr.io/@nodef/extra-math/doc/~/magnitude
|
|
163
|
+
[distance]: https://jsr.io/@nodef/extra-math/doc/~/distance
|
|
164
|
+
[sum]: https://jsr.io/@nodef/extra-math/doc/~/sum
|
|
165
|
+
[product]: https://jsr.io/@nodef/extra-math/doc/~/product
|
|
166
|
+
[median]: https://jsr.io/@nodef/extra-math/doc/~/median
|
|
167
|
+
[modes]: https://jsr.io/@nodef/extra-math/doc/~/modes
|
|
168
|
+
[range]: https://jsr.io/@nodef/extra-math/doc/~/range
|
|
169
|
+
[variance]: https://jsr.io/@nodef/extra-math/doc/~/variance
|
|
170
|
+
[arithmeticMean]: https://jsr.io/@nodef/extra-math/doc/~/arithmeticMean
|
|
171
|
+
[geometricMean]: https://jsr.io/@nodef/extra-math/doc/~/geometricMean
|
|
172
|
+
[harmonicMean]: https://jsr.io/@nodef/extra-math/doc/~/harmonicMean
|
|
173
|
+
[quadriaticMean]: https://jsr.io/@nodef/extra-math/doc/~/quadriaticMean
|
|
174
|
+
[cubicMean]: https://jsr.io/@nodef/extra-math/doc/~/cubicMean
|
package/deno.lock
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "5",
|
|
3
|
+
"specifiers": {
|
|
4
|
+
"jsr:@nodef/extra-number@2": "2.0.0",
|
|
5
|
+
"jsr:@std/assert@^1.0.19": "1.0.19",
|
|
6
|
+
"jsr:@std/cli@^1.0.32": "1.0.32",
|
|
7
|
+
"jsr:@std/fmt@^1.0.10": "1.0.10",
|
|
8
|
+
"jsr:@std/internal@^1.0.12": "1.0.14",
|
|
9
|
+
"jsr:@std/internal@^1.0.14": "1.0.14"
|
|
10
|
+
},
|
|
11
|
+
"jsr": {
|
|
12
|
+
"@nodef/extra-number@2.0.0": {
|
|
13
|
+
"integrity": "fc6ff56e20eac172a2ded9b75a769d8df8615768dc55c00f554a194ba3195dd4"
|
|
14
|
+
},
|
|
15
|
+
"@std/assert@1.0.19": {
|
|
16
|
+
"integrity": "eaada96ee120cb980bc47e040f82814d786fe8162ecc53c91d8df60b8755991e",
|
|
17
|
+
"dependencies": [
|
|
18
|
+
"jsr:@std/internal@^1.0.12"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"@std/cli@1.0.32": {
|
|
22
|
+
"integrity": "188b3a100d6202d64e3f5bd3d799c7fa4f6d77f92cc65eb7f641c1fa0aa92a66",
|
|
23
|
+
"dependencies": [
|
|
24
|
+
"jsr:@std/fmt",
|
|
25
|
+
"jsr:@std/internal@^1.0.14"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"@std/fmt@1.0.10": {
|
|
29
|
+
"integrity": "90dfba288802ac6de82fb31d0917eb9e4450b9925b954d5e51fc29ac07419db5"
|
|
30
|
+
},
|
|
31
|
+
"@std/internal@1.0.14": {
|
|
32
|
+
"integrity": "291516b3d4c35024d6ffbc0a9df5bf4c64116e05b50012cf846710152d2ffdf7"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"workspace": {
|
|
36
|
+
"dependencies": [
|
|
37
|
+
"jsr:@nodef/extra-number@2",
|
|
38
|
+
"jsr:@std/assert@^1.0.19",
|
|
39
|
+
"jsr:@std/cli@^1.0.32"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,351 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
* Round down a number to specific precision.
|
|
3
|
-
* [📘](https://github.com/nodef/extra-math/wiki/floor)
|
|
4
|
-
* @param x a number
|
|
5
|
-
* @param pre to precision (1)
|
|
6
|
-
*/
|
|
7
|
-
declare function floor(x: number, pre?: number): number;
|
|
8
|
-
/**
|
|
9
|
-
* Round up a number to specific precision.
|
|
10
|
-
* [📘](https://github.com/nodef/extra-math/wiki/ceil)
|
|
11
|
-
* @param x a number
|
|
12
|
-
* @param pre to precision [1]
|
|
13
|
-
*/
|
|
14
|
-
declare function ceil(x: number, pre?: number): number;
|
|
15
|
-
/**
|
|
16
|
-
* Round a number to specific precision.
|
|
17
|
-
* [📘](https://github.com/nodef/extra-math/wiki/round)
|
|
18
|
-
* @param x a number
|
|
19
|
-
* @param pre to precision [1]
|
|
20
|
-
*/
|
|
21
|
-
declare function round(x: number, pre?: number): number;
|
|
22
|
-
/**
|
|
23
|
-
* Perform floor-divison of two numbers.
|
|
24
|
-
* [📘](https://github.com/nodef/extra-math/wiki/floorDiv)
|
|
25
|
-
* @param x divisor
|
|
26
|
-
* @param y dividend
|
|
27
|
-
* @returns ⌊x/y⌋
|
|
28
|
-
*/
|
|
29
|
-
declare function floorDiv(x: number, y: number): number;
|
|
30
|
-
/**
|
|
31
|
-
* Perform ceiling-divison of two numbers.
|
|
32
|
-
* [📘](https://github.com/nodef/extra-math/wiki/ceilDiv)
|
|
33
|
-
* @param x divisor
|
|
34
|
-
* @param y dividend
|
|
35
|
-
* @returns ⌈x/y⌉
|
|
36
|
-
*/
|
|
37
|
-
declare function ceilDiv(x: number, y: number): number;
|
|
38
|
-
/**
|
|
39
|
-
* Perform rounded-divison of two numbers.
|
|
40
|
-
* [📘](https://github.com/nodef/extra-math/wiki/roundDiv)
|
|
41
|
-
* @param x divisor
|
|
42
|
-
* @param y dividend
|
|
43
|
-
* @returns [x/y]
|
|
44
|
-
*/
|
|
45
|
-
declare function roundDiv(x: number, y: number): number;
|
|
46
|
-
/**
|
|
47
|
-
* Find the remainder of x/y with sign of x (truncated division).
|
|
48
|
-
* [📘](https://github.com/nodef/extra-math/wiki/rem)
|
|
49
|
-
* @param x dividend
|
|
50
|
-
* @param y divisor
|
|
51
|
-
* @returns trunc(x % y)
|
|
52
|
-
*/
|
|
53
|
-
declare function rem(x: number, y: number): number;
|
|
54
|
-
/**
|
|
55
|
-
* Find the remainder of x/y with sign of y (floored division).
|
|
56
|
-
* [📘](https://github.com/nodef/extra-math/wiki/mod)
|
|
57
|
-
* @param x dividend
|
|
58
|
-
* @param y divisor
|
|
59
|
-
* @returns floor(x % y)
|
|
60
|
-
*/
|
|
61
|
-
declare function mod(x: number, y: number): number;
|
|
62
|
-
/**
|
|
63
|
-
* Find the remainder of x/y with +ve sign (euclidean division).
|
|
64
|
-
* [📘](https://github.com/nodef/extra-math/wiki/modp)
|
|
65
|
-
* @param x dividend
|
|
66
|
-
* @param y divisor
|
|
67
|
-
* @returns n>0: floor(x % y), n<0: ceil(x % y)
|
|
68
|
-
*/
|
|
69
|
-
declare function modp(x: number, y: number): number;
|
|
70
|
-
/**
|
|
71
|
-
* Constrain a number within a minimum and a maximum value.
|
|
72
|
-
* [📘](https://github.com/nodef/extra-math/wiki/constrain)
|
|
73
|
-
* @param x a number
|
|
74
|
-
* @param min minimum value
|
|
75
|
-
* @param max maximum value
|
|
76
|
-
* @returns x<min: min, x>max: max, x
|
|
77
|
-
*/
|
|
78
|
-
declare function constrain(x: number, min: number, max: number): number;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Normalize a number from its current range into a value between 0 and 1.
|
|
82
|
-
* [📘](https://github.com/nodef/extra-math/wiki/normalize)
|
|
83
|
-
* @param x a number
|
|
84
|
-
* @param r lower bound of current range
|
|
85
|
-
* @param R upper bound of current range
|
|
86
|
-
* @returns ∈ [0, 1]
|
|
87
|
-
*/
|
|
88
|
-
declare function normalize(x: number, r: number, R: number): number;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Re-map a number from one range to another.
|
|
92
|
-
* [📘](https://github.com/nodef/extra-math/wiki/remap)
|
|
93
|
-
* @param x a number
|
|
94
|
-
* @param r lower bound of current range
|
|
95
|
-
* @param R upper bound of current range
|
|
96
|
-
* @param t lower bound of target range
|
|
97
|
-
* @param T upper bound of target range
|
|
98
|
-
* @returns ∈ [ymin, ymax]
|
|
99
|
-
*/
|
|
100
|
-
declare function remap(x: number, r: number, R: number, t: number, T: number): number;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Linearly interpolate a number between two numbers.
|
|
104
|
-
* [📘](https://github.com/nodef/extra-math/wiki/lerp)
|
|
105
|
-
* @param x start number
|
|
106
|
-
* @param y stop number
|
|
107
|
-
* @param t interpolant ∈ [0, 1]
|
|
108
|
-
* @returns ∈ [x, y]
|
|
109
|
-
*/
|
|
110
|
-
declare function lerp(x: number, y: number, t: number): number;
|
|
111
|
-
/**
|
|
112
|
-
* Check if a number is a power-of-n.
|
|
113
|
-
* [📘](https://github.com/nodef/extra-math/wiki/isPow)
|
|
114
|
-
* @param x a number
|
|
115
|
-
* @param n base
|
|
116
|
-
* @returns nⁱ = x? | i = +ve integer
|
|
117
|
-
*/
|
|
118
|
-
declare function isPow(x: number, n: number): boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Find largest power-of-n less than or equal to given number.
|
|
121
|
-
* [📘](https://github.com/nodef/extra-math/wiki/prevPow)
|
|
122
|
-
* @param x a number
|
|
123
|
-
* @param n base
|
|
124
|
-
* @returns nⁱ | nⁱ ≤ x and nⁱ > x/n
|
|
125
|
-
*/
|
|
126
|
-
declare function prevPow(x: number, n: number): number;
|
|
127
|
-
/**
|
|
128
|
-
* Find smallest power-of-n greater than or equal to given number.
|
|
129
|
-
* [📘](https://github.com/nodef/extra-math/wiki/nextPow)
|
|
130
|
-
* @param x a number
|
|
131
|
-
* @param n base
|
|
132
|
-
* @returns nⁱ | nⁱ ≥ x and nⁱ < n*x
|
|
133
|
-
*/
|
|
134
|
-
declare function nextPow(x: number, n: number): number;
|
|
135
|
-
/**
|
|
136
|
-
* Find the nth root of a number (ⁿ√).
|
|
137
|
-
* [📘](https://github.com/nodef/extra-math/wiki/root)
|
|
138
|
-
* @param x a number
|
|
139
|
-
* @param n root
|
|
140
|
-
* @returns ⁿ√x
|
|
141
|
-
*/
|
|
142
|
-
declare function root(x: number, n: number): number;
|
|
143
|
-
/**
|
|
144
|
-
* Find the logarithm of a number with a given base.
|
|
145
|
-
* [📘](https://github.com/nodef/extra-math/wiki/log)
|
|
146
|
-
* @param x a number
|
|
147
|
-
* @param b logarithm base [e]
|
|
148
|
-
* @returns log_b (x)
|
|
149
|
-
*/
|
|
150
|
-
declare function log(x: number, b?: number): number;
|
|
151
|
-
/**
|
|
152
|
-
* List all divisors of a number, except itself.
|
|
153
|
-
* [📘](https://github.com/nodef/extra-math/wiki/properDivisors)
|
|
154
|
-
* @param x a number
|
|
155
|
-
* @returns proper divisors (factors)
|
|
156
|
-
*/
|
|
157
|
-
declare function properDivisors(x: number): number[];
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Sum all proper divisors of a number.
|
|
161
|
-
* [📘](https://github.com/nodef/extra-math/wiki/aliquotSum)
|
|
162
|
-
* @param x a number
|
|
163
|
-
* @returns Σdᵢ | dᵢ is a divisor of x and ≠x
|
|
164
|
-
*/
|
|
165
|
-
declare function aliquotSum(x: number): number;
|
|
166
|
-
/**
|
|
167
|
-
* Find the least prime number which divides a number.
|
|
168
|
-
* [📘](https://github.com/nodef/extra-math/wiki/minPrimeFactor)
|
|
169
|
-
* @param x a number
|
|
170
|
-
* @returns least prime factor
|
|
171
|
-
*/
|
|
172
|
-
declare function minPrimeFactor(x: number): number;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Find the greatest prime number which divides a number.
|
|
176
|
-
* [📘](https://github.com/nodef/extra-math/wiki/maxPrimeFactor)
|
|
177
|
-
* @param x a number
|
|
178
|
-
* @returns greatest prime factor
|
|
179
|
-
*/
|
|
180
|
-
declare function maxPrimeFactor(x: number): number;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Find the prime factors of a number.
|
|
184
|
-
* [📘](https://github.com/nodef/extra-math/wiki/primeFactors)
|
|
185
|
-
* @param x a number
|
|
186
|
-
* @returns [f₀, f₁, ...] | fᵢ divides x and is prime
|
|
187
|
-
*/
|
|
188
|
-
declare function primeFactors(x: number): number[];
|
|
189
|
-
/**
|
|
190
|
-
* Find the prime factors and respective exponents of a number.
|
|
191
|
-
* [📘](https://github.com/nodef/extra-math/wiki/primeExponentials)
|
|
192
|
-
* @param x a number
|
|
193
|
-
* @returns [[f₀, e₀], [f₁, e₁], ...] | fᵢ is a prime factor of x and eᵢ is its exponent
|
|
194
|
-
*/
|
|
195
|
-
declare function primeExponentials(x: number): [number, number][];
|
|
196
|
-
/**
|
|
197
|
-
* Examine if number is prime.
|
|
198
|
-
* [📘](https://github.com/nodef/extra-math/wiki/isPrime)
|
|
199
|
-
* @param x a number
|
|
200
|
-
* @returns is divisible by 1 and itself only?
|
|
201
|
-
*/
|
|
202
|
-
declare function isPrime(x: number): boolean;
|
|
203
|
-
/**
|
|
204
|
-
* Find the greatest common divisor of numbers.
|
|
205
|
-
* [📘](https://github.com/nodef/extra-math/wiki/gcd)
|
|
206
|
-
* @param xs a list of numbers
|
|
207
|
-
* @returns gcd(x₁, x₂, ...)
|
|
208
|
-
*/
|
|
209
|
-
declare function gcd(...xs: number[]): number;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Find the least common multiple of numbers.
|
|
213
|
-
* [📘](https://github.com/nodef/extra-math/wiki/lcm)
|
|
214
|
-
* @param xs a list of numbers
|
|
215
|
-
* @returns lcm(x₁, x₂, ...)
|
|
216
|
-
*/
|
|
217
|
-
declare function lcm(...xs: number[]): number;
|
|
218
|
-
/**
|
|
219
|
-
* Find the factorial of a number.
|
|
220
|
-
* [📘](https://github.com/nodef/extra-math/wiki/factorial)
|
|
221
|
-
* @param n a number
|
|
222
|
-
* @param k denominator factorial [0]
|
|
223
|
-
* @returns P(n, k); k=0: n!, k>0: n!/k!
|
|
224
|
-
*/
|
|
225
|
-
declare function factorial(n: number, k?: number): number;
|
|
226
|
-
/**
|
|
227
|
-
* Find the number of ways to choose k elements from a set of n elements.
|
|
228
|
-
* [📘](https://github.com/nodef/extra-math/wiki/binomial)
|
|
229
|
-
* @param n elements in source set
|
|
230
|
-
* @param k elements in choose set
|
|
231
|
-
* @returns C(n, k)
|
|
232
|
-
*/
|
|
233
|
-
declare function binomial(n: number, k: number): number;
|
|
234
|
-
/**
|
|
235
|
-
* Find the number of ways to put n objects in m bins (n=sum(kᵢ)).
|
|
236
|
-
* [📘](https://github.com/nodef/extra-math/wiki/multinomial)
|
|
237
|
-
* @param ks objects per bin (kᵢ)
|
|
238
|
-
* @returns n!/(k₁!k₂!...) | n=sum(kᵢ)
|
|
239
|
-
*/
|
|
240
|
-
declare function multinomial(...ks: number[]): number;
|
|
241
|
-
/**
|
|
242
|
-
* Convert radians to degrees.
|
|
243
|
-
* [📘](https://github.com/nodef/extra-math/wiki/degrees)
|
|
244
|
-
* @param x radians
|
|
245
|
-
* @returns 2π → 360
|
|
246
|
-
*/
|
|
247
|
-
declare function degrees(x: number): number;
|
|
248
|
-
/**
|
|
249
|
-
* Convert degrees to radians.
|
|
250
|
-
* [📘](https://github.com/nodef/extra-math/wiki/radians)
|
|
251
|
-
* @param x degrees
|
|
252
|
-
* @returns 360 → 2π
|
|
253
|
-
*/
|
|
254
|
-
declare function radians(x: number): number;
|
|
255
|
-
/**
|
|
256
|
-
* Find the sum of numbers (Σ).
|
|
257
|
-
* [📘](https://github.com/nodef/extra-math/wiki/sum)
|
|
258
|
-
* @param xs a list of numbers
|
|
259
|
-
* @returns Σxᵢ
|
|
260
|
-
*/
|
|
261
|
-
declare function sum(...xs: number[]): number;
|
|
262
|
-
/**
|
|
263
|
-
* Find the product of numbers (∏).
|
|
264
|
-
* [📘](https://github.com/nodef/extra-math/wiki/product)
|
|
265
|
-
* @param xs a list of numbers
|
|
266
|
-
* @returns ∏xᵢ
|
|
267
|
-
*/
|
|
268
|
-
declare function product(...xs: number[]): number;
|
|
269
|
-
/**
|
|
270
|
-
* Find the value separating the higher and lower halves of numbers.
|
|
271
|
-
* [📘](https://github.com/nodef/extra-math/wiki/median)
|
|
272
|
-
* @param xs a list of numbers
|
|
273
|
-
* @returns xₘ | sort(xs) = [..., xₘ, ...]
|
|
274
|
-
*/
|
|
275
|
-
declare function median(...xs: number[]): number;
|
|
276
|
-
/**
|
|
277
|
-
* Find the values that appear most often.
|
|
278
|
-
* [📘](https://github.com/nodef/extra-math/wiki/modes)
|
|
279
|
-
* @param xs a list of numbers
|
|
280
|
-
* @returns [xₘ₁, xₘ₂, ...] | count(xₘᵢ) ≥ count(xᵢ) ∀ xᵢ ∈ xs
|
|
281
|
-
*/
|
|
282
|
-
declare function modes(...xs: number[]): number[];
|
|
283
|
-
/**
|
|
284
|
-
* Find the smallest and largest values.
|
|
285
|
-
* [📘](https://github.com/nodef/extra-math/wiki/range)
|
|
286
|
-
* @param xs a list of numbers
|
|
287
|
-
* @returns [min(xs), max(xs)]
|
|
288
|
-
*/
|
|
289
|
-
declare function range(...xs: number[]): [number, number];
|
|
290
|
-
/**
|
|
291
|
-
* Find the mean of squared deviation of numbers from its mean.
|
|
292
|
-
* [📘](https://github.com/nodef/extra-math/wiki/variance)
|
|
293
|
-
* @param xs a list of numbers
|
|
294
|
-
* @returns σ² = E[(xs - µ)²] | µ = mean(xs)
|
|
295
|
-
*/
|
|
296
|
-
declare function variance(...xs: number[]): number;
|
|
297
|
-
/**
|
|
298
|
-
* Find the average of numbers.
|
|
299
|
-
* [📘](https://github.com/nodef/extra-math/wiki/arithmeticMean)
|
|
300
|
-
* @param xs a list of numbers
|
|
301
|
-
* @returns Σxᵢ/n | n = size(xs)
|
|
302
|
-
*/
|
|
303
|
-
declare function arithmeticMean(...xs: number[]): number;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Find the geometric mean of numbers.
|
|
307
|
-
* [📘](https://github.com/nodef/extra-math/wiki/geometricMean)
|
|
308
|
-
* @param xs a list of numbers
|
|
309
|
-
* @returns ⁿ√(∏xᵢ) | n = size(xs)
|
|
310
|
-
*/
|
|
311
|
-
declare function geometricMean(...xs: number[]): number;
|
|
312
|
-
/**
|
|
313
|
-
* Find the harmonic mean of numbers.
|
|
314
|
-
* [📘](https://github.com/nodef/extra-math/wiki/harmonicMean)
|
|
315
|
-
* @param xs a list of numbers
|
|
316
|
-
* @returns n/Σ(1/xᵢ) | n = size(xs)
|
|
317
|
-
*/
|
|
318
|
-
declare function harmonicMean(...xs: number[]): number;
|
|
319
|
-
/**
|
|
320
|
-
* Find the quadriatic mean of numbers.
|
|
321
|
-
* [📘](https://github.com/nodef/extra-math/wiki/quadriaticMean)
|
|
322
|
-
* @param xs a list of numbers
|
|
323
|
-
* @returns √(Σxᵢ²)/n | n = size(xs)
|
|
324
|
-
*/
|
|
325
|
-
declare function quadriaticMean(...xs: number[]): number;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Find the cubic mean of numbers.
|
|
329
|
-
* [📘](https://github.com/nodef/extra-math/wiki/cubicMean)
|
|
330
|
-
* @param xs a list of numbers
|
|
331
|
-
* @returns ³√(Σxᵢ³)/n | n = size(xs)
|
|
332
|
-
*/
|
|
333
|
-
declare function cubicMean(...xs: number[]): number;
|
|
334
|
-
|
|
1
|
+
export { floor, ceil, round, floorDiv, ceilDiv, roundDiv, rem, mod, modp, constrain, constrain as clamp, normalize, normalize as norm, lerp, remap, remap as map, isPow, prevPow, nextPow, root, log, properDivisors, properDivisors as aliquotParts, aliquotSum, minPrimeFactor, minPrimeFactor as leastPrimeFactor, maxPrimeFactor, maxPrimeFactor as greatestPrimeFactor, primeFactors, primeExponentials, isPrime, gcd, gcd as hcf, lcm, factorial, binomial, multinomial, degrees, radians, sum, product, median, modes, range, variance, arithmeticMean, arithmeticMean as mean, geometricMean, harmonicMean, quadriaticMean, quadriaticMean as rootMeanSquare, cubicMean } from "@nodef/extra-number";
|
|
335
2
|
/**
|
|
336
3
|
* Calculate the magnitude (length) of a vector.
|
|
337
|
-
* [📘](https://github.com/nodef/extra-math/wiki/magnitude)
|
|
338
4
|
* @param xs vector ([x, y, z, ...])
|
|
339
5
|
* @returns √(x² + y² + z²)
|
|
340
|
-
|
|
341
|
-
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* xmath.magnitude([5, 9]);
|
|
9
|
+
* // → 10.295630140987
|
|
10
|
+
*
|
|
11
|
+
* xmath.magnitude([10, 2, -1]);
|
|
12
|
+
* // → 10.246950765959598
|
|
13
|
+
* ```
|
|
14
|
+
*/ export declare function magnitude(xs: number[]): number;
|
|
342
15
|
/**
|
|
343
16
|
* Calculate the distance between two points.
|
|
344
|
-
* [📘](https://github.com/nodef/extra-math/wiki/distance)
|
|
345
17
|
* @param xs first point ([x, y, z, ...])
|
|
346
18
|
* @param ys second point ([x, y, z, ...])
|
|
347
19
|
* @returns √(Δx² + Δy² + Δz²)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
20
|
+
* @example
|
|
21
|
+
* ```javascript
|
|
22
|
+
* xmath.distance([2, -6], [7, 3]);
|
|
23
|
+
* // → 10.295630140987
|
|
24
|
+
*
|
|
25
|
+
* xmath.distance([7, 4, 3], [17, 6, 2]);
|
|
26
|
+
* // → 10.246950765959598
|
|
27
|
+
* ```
|
|
28
|
+
*/ export declare function distance(xs: number[], ys: number[]): number;
|