@thi.ng/math 5.1.1 → 5.3.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2021-11-19T07:59:51Z
3
+ - **Last updated**: 2022-03-11T12:13:49Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,22 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [5.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.3.0) (2022-03-11)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add ldiv() ([35d1e97](https://github.com/thi-ng/umbrella/commit/35d1e97))
17
+
18
+ ## [5.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.2.0) (2021-12-13)
19
+
20
+ #### 🚀 Features
21
+
22
+ - add prime number fns ([f301256](https://github.com/thi-ng/umbrella/commit/f301256))
23
+ - add nearestPrime()
24
+ - add primesUntil()
25
+ - add tests
26
+ - update pkg
27
+
12
28
  ## [5.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.1.0) (2021-11-17)
13
29
 
14
30
  #### 🚀 Features
package/README.md CHANGED
@@ -71,7 +71,7 @@ node --experimental-repl-await
71
71
  > const math = await import("@thi.ng/math");
72
72
  ```
73
73
 
74
- Package sizes (gzipped, pre-treeshake): ESM: 4.11 KB
74
+ Package sizes (gzipped, pre-treeshake): ESM: 4.29 KB
75
75
 
76
76
  ## Dependencies
77
77
 
@@ -125,4 +125,4 @@ If this project contributes to an academic publication, please cite it as:
125
125
 
126
126
  ## License
127
127
 
128
- © 2013 - 2021 Karsten Schmidt // Apache Software License 2.0
128
+ © 2013 - 2022 Karsten Schmidt // Apache Software License 2.0
package/api.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare const PHI: number;
13
13
  export declare const SQRT2: number;
14
14
  export declare const SQRT3: number;
15
15
  export declare const SQRT2_2: number;
16
- export declare const SQRT2_3: number;
16
+ export declare const SQRT3_2: number;
17
17
  export declare const THIRD: number;
18
18
  export declare const TWO_THIRD: number;
19
19
  export declare const SIXTH: number;
package/api.js CHANGED
@@ -13,7 +13,7 @@ export const PHI = (1 + Math.sqrt(5)) / 2;
13
13
  export const SQRT2 = Math.SQRT2;
14
14
  export const SQRT3 = Math.sqrt(3);
15
15
  export const SQRT2_2 = SQRT2 / 2;
16
- export const SQRT2_3 = SQRT3 / 2;
16
+ export const SQRT3_2 = SQRT3 / 2;
17
17
  export const THIRD = 1 / 3;
18
18
  export const TWO_THIRD = 2 / 3;
19
19
  export const SIXTH = 1 / 6;
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./libc.js";
11
11
  export * from "./min-error.js";
12
12
  export * from "./mix.js";
13
13
  export * from "./prec.js";
14
+ export * from "./prime.js";
14
15
  export * from "./ratio.js";
15
16
  export * from "./safe-div.js";
16
17
  export * from "./solve.js";
package/index.js CHANGED
@@ -11,6 +11,7 @@ export * from "./libc.js";
11
11
  export * from "./min-error.js";
12
12
  export * from "./mix.js";
13
13
  export * from "./prec.js";
14
+ export * from "./prime.js";
14
15
  export * from "./ratio.js";
15
16
  export * from "./safe-div.js";
16
17
  export * from "./solve.js";
package/interval.d.ts CHANGED
@@ -10,25 +10,25 @@ export declare const clamp: FnN3;
10
10
  /**
11
11
  * Clamps value `x` to closed [0 .. ∞] interval.
12
12
  *
13
- * @param x
13
+ * @param x -
14
14
  */
15
15
  export declare const clamp0: FnN;
16
16
  /**
17
17
  * Clamps value `x` to closed [0 .. 1] interval.
18
18
  *
19
- * @param x
19
+ * @param x -
20
20
  */
21
21
  export declare const clamp01: FnN;
22
22
  /**
23
23
  * Clamps value `x` to closed [-1 .. 1] interval.
24
24
  *
25
- * @param x
25
+ * @param x -
26
26
  */
27
27
  export declare const clamp11: FnN;
28
28
  /**
29
29
  * Clamps value `x` to closed [0 .. 0.5] interval.
30
30
  *
31
- * @param x
31
+ * @param x -
32
32
  */
33
33
  export declare const clamp05: FnN;
34
34
  /**
@@ -71,16 +71,16 @@ export declare const max4id: FnN4;
71
71
  /**
72
72
  * Returns the non-zero minimum value of the given `a`, `b` args.
73
73
  *
74
- * @param a
75
- * @param b
74
+ * @param a -
75
+ * @param b -
76
76
  */
77
77
  export declare const minNonZero2: FnN2;
78
78
  /**
79
79
  * Returns the non-zero minimum value of the given `a`, `b`, `c` args.
80
80
  *
81
- * @param a
82
- * @param b
83
- * @param c
81
+ * @param a -
82
+ * @param b -
83
+ * @param c -
84
84
  */
85
85
  export declare const minNonZero3: FnN3;
86
86
  /**
package/interval.js CHANGED
@@ -9,25 +9,25 @@ export const clamp = (x, min, max) => (x < min ? min : x > max ? max : x);
9
9
  /**
10
10
  * Clamps value `x` to closed [0 .. ∞] interval.
11
11
  *
12
- * @param x
12
+ * @param x -
13
13
  */
14
14
  export const clamp0 = (x) => (x > 0 ? x : 0);
15
15
  /**
16
16
  * Clamps value `x` to closed [0 .. 1] interval.
17
17
  *
18
- * @param x
18
+ * @param x -
19
19
  */
20
20
  export const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);
21
21
  /**
22
22
  * Clamps value `x` to closed [-1 .. 1] interval.
23
23
  *
24
- * @param x
24
+ * @param x -
25
25
  */
26
26
  export const clamp11 = (x) => (x < -1 ? -1 : x > 1 ? 1 : x);
27
27
  /**
28
28
  * Clamps value `x` to closed [0 .. 0.5] interval.
29
29
  *
30
- * @param x
30
+ * @param x -
31
31
  */
32
32
  export const clamp05 = (x) => (x < 0 ? 0 : x > 0.5 ? 0.5 : x);
33
33
  /**
@@ -114,16 +114,16 @@ export const max4id = (a, b, c, d) => a >= b
114
114
  /**
115
115
  * Returns the non-zero minimum value of the given `a`, `b` args.
116
116
  *
117
- * @param a
118
- * @param b
117
+ * @param a -
118
+ * @param b -
119
119
  */
120
120
  export const minNonZero2 = (a, b) => a !== 0 ? (b !== 0 ? Math.min(a, b) : a) : b;
121
121
  /**
122
122
  * Returns the non-zero minimum value of the given `a`, `b`, `c` args.
123
123
  *
124
- * @param a
125
- * @param b
126
- * @param c
124
+ * @param a -
125
+ * @param b -
126
+ * @param c -
127
127
  */
128
128
  export const minNonZero3 = (a, b, c) => minNonZero2(minNonZero2(a, b), c);
129
129
  /**
package/libc.d.ts CHANGED
@@ -1,31 +1,31 @@
1
- import type { FnN, FnN2, FnN3 } from "@thi.ng/api";
1
+ import type { FnN, FnN2, FnN3, FnU2 } from "@thi.ng/api";
2
2
  /**
3
3
  * Returns a value with the magnitude of `x` and the sign of `y`.
4
4
  *
5
- * @param x
6
- * @param y
5
+ * @param x -
6
+ * @param y -
7
7
  */
8
8
  export declare const copysign: FnN2;
9
9
  /**
10
10
  * Returns `2^x`.
11
11
  *
12
- * @param x
12
+ * @param x -
13
13
  */
14
14
  export declare const exp2: FnN;
15
15
  /**
16
16
  * Returns the positive difference between `x` and `y`, i.e. `x - y` iff `x > y`,
17
17
  * otherwise zero.
18
18
  *
19
- * @param x
20
- * @param y
19
+ * @param x -
20
+ * @param y -
21
21
  */
22
22
  export declare const fdim: FnN2;
23
23
  /**
24
24
  * Returns `x * y + z`.
25
25
  *
26
- * @param x
27
- * @param y
28
- * @param z
26
+ * @param x -
27
+ * @param y -
28
+ * @param z -
29
29
  */
30
30
  export declare const fma: FnN3;
31
31
  /**
@@ -42,8 +42,8 @@ export declare const fma: FnN3;
42
42
  *
43
43
  * Reference: https://www.cplusplus.com/reference/cmath/fmod/
44
44
  *
45
- * @param x
46
- * @param y
45
+ * @param x -
46
+ * @param y -
47
47
  */
48
48
  export declare const fmod: FnN2;
49
49
  /**
@@ -59,14 +59,14 @@ export declare const fmod: FnN2;
59
59
  * Based on:
60
60
  * https://github.com/locutusjs/locutus/blob/master/src/c/math/frexp.js
61
61
  *
62
- * @param x
62
+ * @param x -
63
63
  */
64
64
  export declare const frexp: (x: number) => number[];
65
65
  /**
66
66
  * Inverse op of {@link frexp}. Returns `x * 2^exp`
67
67
  *
68
- * @param x
69
- * @param exp
68
+ * @param x -
69
+ * @param exp -
70
70
  */
71
71
  export declare const ldexp: FnN2;
72
72
  /**
@@ -75,8 +75,16 @@ export declare const ldexp: FnN2;
75
75
  * @remarks
76
76
  * https://www.cplusplus.com/reference/cmath/remainder/
77
77
  *
78
- * @param x
79
- * @param y
78
+ * @param x -
79
+ * @param y -
80
80
  */
81
81
  export declare const remainder: FnN2;
82
+ /**
83
+ * Computes both the quotient and remainder of the integer division of the
84
+ * numerator `x` by the denominator `y`.
85
+ *
86
+ * @param x -
87
+ * @param y -
88
+ */
89
+ export declare const ldiv: FnU2<number, [number, number]>;
82
90
  //# sourceMappingURL=libc.d.ts.map
package/libc.js CHANGED
@@ -1,30 +1,30 @@
1
1
  /**
2
2
  * Returns a value with the magnitude of `x` and the sign of `y`.
3
3
  *
4
- * @param x
5
- * @param y
4
+ * @param x -
5
+ * @param y -
6
6
  */
7
7
  export const copysign = (x, y) => Math.sign(y) * Math.abs(x);
8
8
  /**
9
9
  * Returns `2^x`.
10
10
  *
11
- * @param x
11
+ * @param x -
12
12
  */
13
13
  export const exp2 = (x) => 2 ** x;
14
14
  /**
15
15
  * Returns the positive difference between `x` and `y`, i.e. `x - y` iff `x > y`,
16
16
  * otherwise zero.
17
17
  *
18
- * @param x
19
- * @param y
18
+ * @param x -
19
+ * @param y -
20
20
  */
21
21
  export const fdim = (x, y) => Math.max(x - y, 0);
22
22
  /**
23
23
  * Returns `x * y + z`.
24
24
  *
25
- * @param x
26
- * @param y
27
- * @param z
25
+ * @param x -
26
+ * @param y -
27
+ * @param z -
28
28
  */
29
29
  export const fma = (x, y, z) => x * y + z;
30
30
  /**
@@ -41,8 +41,8 @@ export const fma = (x, y, z) => x * y + z;
41
41
  *
42
42
  * Reference: https://www.cplusplus.com/reference/cmath/fmod/
43
43
  *
44
- * @param x
45
- * @param y
44
+ * @param x -
45
+ * @param y -
46
46
  */
47
47
  export const fmod = (x, y) => x % y;
48
48
  //export const fmod: FnN2 = (x, y) => x - y * Math.trunc(x / y);
@@ -59,7 +59,7 @@ export const fmod = (x, y) => x % y;
59
59
  * Based on:
60
60
  * https://github.com/locutusjs/locutus/blob/master/src/c/math/frexp.js
61
61
  *
62
- * @param x
62
+ * @param x -
63
63
  */
64
64
  export const frexp = (x) => {
65
65
  if (x === 0 || !isFinite(x))
@@ -80,8 +80,8 @@ export const frexp = (x) => {
80
80
  /**
81
81
  * Inverse op of {@link frexp}. Returns `x * 2^exp`
82
82
  *
83
- * @param x
84
- * @param exp
83
+ * @param x -
84
+ * @param exp -
85
85
  */
86
86
  export const ldexp = (x, exp) => x * 2 ** exp;
87
87
  /**
@@ -90,7 +90,20 @@ export const ldexp = (x, exp) => x * 2 ** exp;
90
90
  * @remarks
91
91
  * https://www.cplusplus.com/reference/cmath/remainder/
92
92
  *
93
- * @param x
94
- * @param y
93
+ * @param x -
94
+ * @param y -
95
95
  */
96
96
  export const remainder = (x, y) => x - y * Math.round(x / y);
97
+ /**
98
+ * Computes both the quotient and remainder of the integer division of the
99
+ * numerator `x` by the denominator `y`.
100
+ *
101
+ * @param x -
102
+ * @param y -
103
+ */
104
+ export const ldiv = (x, y) => {
105
+ x |= 0;
106
+ y |= 0;
107
+ const q = (x / y) | 0;
108
+ return [q, x - q * y];
109
+ };
package/mix.d.ts CHANGED
@@ -77,11 +77,11 @@ export declare const mixCubicHermite: FnN5;
77
77
  * spaced) and computes tangents automatically. Returns `b` iff `t=0` and `c`
78
78
  * iff `t=1.0`.
79
79
  *
80
- * @param a
81
- * @param b
82
- * @param c
83
- * @param d
84
- * @param t
80
+ * @param a -
81
+ * @param b -
82
+ * @param c -
83
+ * @param d -
84
+ * @param t -
85
85
  */
86
86
  export declare const mixCubicHermiteFromPoints: FnN5;
87
87
  /**
@@ -92,25 +92,24 @@ export declare const mixCubicHermiteFromPoints: FnN5;
92
92
  * Result will not be clamped and might fall outside the total range of the
93
93
  * input samples.
94
94
  *
95
- * @param s00
96
- * @param s01
97
- * @param s02
98
- * @param s03
99
- * @param s10
100
- * @param s11
101
- * @param s12
102
- * @param s13
103
- * @param s20
104
- * @param s21
105
- * @param s22
106
- * @param s23
107
- * @param s30
108
- * @param s31
109
- * @param s32
110
- * @param s33
111
- * @param u
112
- * @param v
113
- * @returns
95
+ * @param s00 -
96
+ * @param s01 -
97
+ * @param s02 -
98
+ * @param s03 -
99
+ * @param s10 -
100
+ * @param s11 -
101
+ * @param s12 -
102
+ * @param s13 -
103
+ * @param s20 -
104
+ * @param s21 -
105
+ * @param s22 -
106
+ * @param s23 -
107
+ * @param s30 -
108
+ * @param s31 -
109
+ * @param s32 -
110
+ * @param s33 -
111
+ * @param u -
112
+ * @param v -
114
113
  */
115
114
  export declare const mixBicubic: (s00: number, s01: number, s02: number, s03: number, s10: number, s11: number, s12: number, s13: number, s20: number, s21: number, s22: number, s23: number, s30: number, s31: number, s32: number, s33: number, u: number, v: number) => number;
116
115
  /**
@@ -235,8 +234,8 @@ export declare const cubicPulse: FnN3;
235
234
  * @remarks
236
235
  * https://en.wikipedia.org/wiki/Sinc_function
237
236
  *
238
- * @param k
239
- * @param t
237
+ * @param k -
238
+ * @param t -
240
239
  */
241
240
  export declare const sinc: FnN;
242
241
  /**
@@ -247,8 +246,8 @@ export declare const sinc: FnN;
247
246
  *
248
247
  * @see {@link sinc}
249
248
  *
250
- * @param k
251
- * @param t
249
+ * @param k -
250
+ * @param t -
252
251
  */
253
252
  export declare const sincNormalized: FnN2;
254
253
  /**
@@ -258,8 +257,8 @@ export declare const sincNormalized: FnN2;
258
257
  * @remarks
259
258
  * Interactive graph: https://www.desmos.com/calculator/pmypqgefle
260
259
  *
261
- * @param a
262
- * @param t
260
+ * @param a -
261
+ * @param t -
263
262
  */
264
263
  export declare const lanczos: FnN2;
265
264
  /**
@@ -306,9 +305,9 @@ export declare const schlick: FnN3;
306
305
  * `num` steps. I.e. multiplying `a` with the returned factor will yield
307
306
  * `b` after `num` steps. All args must be > 0.
308
307
  *
309
- * @param a
310
- * @param b
311
- * @param num
308
+ * @param a -
309
+ * @param b -
310
+ * @param num -
312
311
  */
313
312
  export declare const expFactor: FnN3;
314
313
  /**
@@ -317,9 +316,9 @@ export declare const expFactor: FnN3;
317
316
  * @remarks
318
317
  * Interactive graph: https://www.desmos.com/calculator/aq6hdzxprv
319
318
  *
320
- * @param bias
321
- * @param sigma
322
- * @param t
319
+ * @param bias -
320
+ * @param sigma -
321
+ * @param t -
323
322
  */
324
323
  export declare const gaussian: FnN3;
325
324
  //# sourceMappingURL=mix.d.ts.map
package/mix.js CHANGED
@@ -102,11 +102,11 @@ export const mixCubicHermite = (a, ta, b, tb, t) => {
102
102
  * spaced) and computes tangents automatically. Returns `b` iff `t=0` and `c`
103
103
  * iff `t=1.0`.
104
104
  *
105
- * @param a
106
- * @param b
107
- * @param c
108
- * @param d
109
- * @param t
105
+ * @param a -
106
+ * @param b -
107
+ * @param c -
108
+ * @param d -
109
+ * @param t -
110
110
  */
111
111
  export const mixCubicHermiteFromPoints = (a, b, c, d, t) => {
112
112
  d *= 0.5;
@@ -125,25 +125,24 @@ export const mixCubicHermiteFromPoints = (a, b, c, d, t) => {
125
125
  * Result will not be clamped and might fall outside the total range of the
126
126
  * input samples.
127
127
  *
128
- * @param s00
129
- * @param s01
130
- * @param s02
131
- * @param s03
132
- * @param s10
133
- * @param s11
134
- * @param s12
135
- * @param s13
136
- * @param s20
137
- * @param s21
138
- * @param s22
139
- * @param s23
140
- * @param s30
141
- * @param s31
142
- * @param s32
143
- * @param s33
144
- * @param u
145
- * @param v
146
- * @returns
128
+ * @param s00 -
129
+ * @param s01 -
130
+ * @param s02 -
131
+ * @param s03 -
132
+ * @param s10 -
133
+ * @param s11 -
134
+ * @param s12 -
135
+ * @param s13 -
136
+ * @param s20 -
137
+ * @param s21 -
138
+ * @param s22 -
139
+ * @param s23 -
140
+ * @param s30 -
141
+ * @param s31 -
142
+ * @param s32 -
143
+ * @param s33 -
144
+ * @param u -
145
+ * @param v -
147
146
  */
148
147
  export const mixBicubic = (s00, s01, s02, s03, s10, s11, s12, s13, s20, s21, s22, s23, s30, s31, s32, s33, u, v) => mixCubicHermiteFromPoints(mixCubicHermiteFromPoints(s00, s01, s02, s03, u), mixCubicHermiteFromPoints(s10, s11, s12, s13, u), mixCubicHermiteFromPoints(s20, s21, s22, s23, u), mixCubicHermiteFromPoints(s30, s31, s32, s33, u), v);
149
148
  /**
@@ -285,8 +284,8 @@ export const cubicPulse = (w, c, t) => {
285
284
  * @remarks
286
285
  * https://en.wikipedia.org/wiki/Sinc_function
287
286
  *
288
- * @param k
289
- * @param t
287
+ * @param k -
288
+ * @param t -
290
289
  */
291
290
  export const sinc = (t) => (t !== 0 ? Math.sin(t) / t : 1);
292
291
  /**
@@ -297,8 +296,8 @@ export const sinc = (t) => (t !== 0 ? Math.sin(t) / t : 1);
297
296
  *
298
297
  * @see {@link sinc}
299
298
  *
300
- * @param k
301
- * @param t
299
+ * @param k -
300
+ * @param t -
302
301
  */
303
302
  export const sincNormalized = (k, t) => sinc(PI * k * t);
304
303
  /**
@@ -308,8 +307,8 @@ export const sincNormalized = (k, t) => sinc(PI * k * t);
308
307
  * @remarks
309
308
  * Interactive graph: https://www.desmos.com/calculator/pmypqgefle
310
309
  *
311
- * @param a
312
- * @param t
310
+ * @param a -
311
+ * @param t -
313
312
  */
314
313
  export const lanczos = (a, t) => t !== 0 ? (-a < t && t < a ? sinc(PI * t) * sinc((PI * t) / a) : 0) : 1;
315
314
  /**
@@ -358,9 +357,9 @@ export const schlick = (a, b, t) => t <= b
358
357
  * `num` steps. I.e. multiplying `a` with the returned factor will yield
359
358
  * `b` after `num` steps. All args must be > 0.
360
359
  *
361
- * @param a
362
- * @param b
363
- * @param num
360
+ * @param a -
361
+ * @param b -
362
+ * @param num -
364
363
  */
365
364
  export const expFactor = (a, b, num) => (b / a) ** (1 / num);
366
365
  /**
@@ -369,8 +368,8 @@ export const expFactor = (a, b, num) => (b / a) ** (1 / num);
369
368
  * @remarks
370
369
  * Interactive graph: https://www.desmos.com/calculator/aq6hdzxprv
371
370
  *
372
- * @param bias
373
- * @param sigma
374
- * @param t
371
+ * @param bias -
372
+ * @param sigma -
373
+ * @param t -
375
374
  */
376
375
  export const gaussian = (bias, sigma, t) => Math.exp(-((t - bias) ** 2) / (2 * sigma * sigma));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/math",
3
- "version": "5.1.1",
3
+ "version": "5.3.0",
4
4
  "description": "Assorted common math functions & utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,15 +34,15 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.1"
37
+ "@thi.ng/api": "^8.3.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@microsoft/api-extractor": "^7.18.19",
41
- "@thi.ng/testament": "^0.2.1",
40
+ "@microsoft/api-extractor": "^7.19.4",
41
+ "@thi.ng/testament": "^0.2.4",
42
42
  "rimraf": "^3.0.2",
43
43
  "tools": "^0.0.1",
44
- "typedoc": "^0.22.9",
45
- "typescript": "^4.5.2"
44
+ "typedoc": "^0.22.13",
45
+ "typescript": "^4.6.2"
46
46
  },
47
47
  "keywords": [
48
48
  "animation",
@@ -52,6 +52,7 @@
52
52
  "interpolation",
53
53
  "interval",
54
54
  "math",
55
+ "prime",
55
56
  "quadratic",
56
57
  "smooth",
57
58
  "solver",
@@ -112,6 +113,9 @@
112
113
  "./prec": {
113
114
  "import": "./prec.js"
114
115
  },
116
+ "./prime": {
117
+ "import": "./prime.js"
118
+ },
115
119
  "./ratio": {
116
120
  "import": "./ratio.js"
117
121
  },
@@ -128,5 +132,5 @@
128
132
  "thi.ng": {
129
133
  "year": 2013
130
134
  },
131
- "gitHead": "8bd27c8bde0b770e7c001943f11c951cd345d668\n"
135
+ "gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
132
136
  }
package/prime.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Returns iterator of all prime numbers ≤ given `x` using Sieve of
3
+ * Eratosthenes.
4
+ *
5
+ * @remarks
6
+ * Reference: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
7
+ *
8
+ * @param x -
9
+ */
10
+ export declare function primesUntil(x: number): Generator<number, void, unknown>;
11
+ /**
12
+ * Returns largest prime number ≤ given `x` using Sieve of Eratosthenes. Returns
13
+ * -1 if x < 1.
14
+ *
15
+ * @remarks
16
+ * Reference: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
17
+ *
18
+ * @param x -
19
+ */
20
+ export declare const nearestPrime: (x: number) => number;
21
+ //# sourceMappingURL=prime.d.ts.map
package/prime.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Returns iterator of all prime numbers ≤ given `x` using Sieve of
3
+ * Eratosthenes.
4
+ *
5
+ * @remarks
6
+ * Reference: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
7
+ *
8
+ * @param x -
9
+ */
10
+ export function* primesUntil(x) {
11
+ if (x < 1)
12
+ return;
13
+ yield 1;
14
+ const sieve = [];
15
+ const max = Math.sqrt(x) | 0;
16
+ for (let i = 2; i <= x; i++) {
17
+ if (!sieve[i]) {
18
+ yield i;
19
+ __updateSieve(sieve, i, x, max);
20
+ }
21
+ }
22
+ }
23
+ /**
24
+ * Returns largest prime number ≤ given `x` using Sieve of Eratosthenes. Returns
25
+ * -1 if x < 1.
26
+ *
27
+ * @remarks
28
+ * Reference: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
29
+ *
30
+ * @param x -
31
+ */
32
+ export const nearestPrime = (x) => {
33
+ if (x < 1)
34
+ return -1;
35
+ let prime = 1;
36
+ const sieve = [];
37
+ const max = Math.sqrt(x) | 0;
38
+ for (let i = 2; i <= x; i++) {
39
+ if (!sieve[i]) {
40
+ prime = i;
41
+ __updateSieve(sieve, i, x, max);
42
+ }
43
+ }
44
+ return prime;
45
+ };
46
+ /**
47
+ * @internal
48
+ */
49
+ const __updateSieve = (sieve, i, x, max) => {
50
+ if (i <= max) {
51
+ for (let j = i * i; j <= x; j += i)
52
+ sieve[j] = true;
53
+ }
54
+ };
package/safe-div.d.ts CHANGED
@@ -2,8 +2,8 @@ import type { FnN2 } from "@thi.ng/api";
2
2
  /**
3
3
  * Returns `a` divided by `b` or zero if `b = 0`.
4
4
  *
5
- * @param a
6
- * @param b
5
+ * @param a -
6
+ * @param b -
7
7
  */
8
8
  export declare const safeDiv: FnN2;
9
9
  //# sourceMappingURL=safe-div.d.ts.map
package/safe-div.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Returns `a` divided by `b` or zero if `b = 0`.
3
3
  *
4
- * @param a
5
- * @param b
4
+ * @param a -
5
+ * @param b -
6
6
  */
7
7
  export const safeDiv = (a, b) => (b !== 0 ? a / b : 0);