@thi.ng/binary 3.1.3 → 3.2.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 +7 -1
- package/README.md +2 -2
- package/float.d.ts +14 -14
- package/float.js +14 -14
- package/one-hot.d.ts +2 -2
- package/one-hot.js +2 -2
- package/package.json +7 -7
- package/rotate.d.ts +8 -0
- package/rotate.js +8 -0
- package/splat.d.ts +2 -2
- package/splat.js +2 -2
- package/swizzle.d.ts +6 -6
- package/swizzle.js +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
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,12 @@ 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
|
+
## [3.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/binary@3.2.0) (2022-03-11)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add shiftRL() ([804565e](https://github.com/thi-ng/umbrella/commit/804565e))
|
|
17
|
+
|
|
12
18
|
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/binary@3.1.0) (2021-11-17)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ node --experimental-repl-await
|
|
|
56
56
|
> const binary = await import("@thi.ng/binary");
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
Package sizes (gzipped, pre-treeshake): ESM: 2.
|
|
59
|
+
Package sizes (gzipped, pre-treeshake): ESM: 2.19 KB
|
|
60
60
|
|
|
61
61
|
## Dependencies
|
|
62
62
|
|
|
@@ -97,4 +97,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
97
97
|
|
|
98
98
|
## License
|
|
99
99
|
|
|
100
|
-
© 2016 -
|
|
100
|
+
© 2016 - 2022 Karsten Schmidt // Apache Software License 2.0
|
package/float.d.ts
CHANGED
|
@@ -11,28 +11,28 @@ export declare const uintBitsToFloat: FnN;
|
|
|
11
11
|
* Returns i32 representation of f64 as [hi, lo] tuple (takes
|
|
12
12
|
* environment's Little Endianess into account).
|
|
13
13
|
*
|
|
14
|
-
* @param x
|
|
14
|
+
* @param x -
|
|
15
15
|
*/
|
|
16
16
|
export declare const floatToIntBits64: (x: number) => [number, number];
|
|
17
17
|
/**
|
|
18
18
|
* Returns u32 representation of f64 as [hi, lo] tuple (takes
|
|
19
19
|
* environment's Little Endianess into account).
|
|
20
20
|
*
|
|
21
|
-
* @param x
|
|
21
|
+
* @param x -
|
|
22
22
|
*/
|
|
23
23
|
export declare const floatToUintBits64: (x: number) => [number, number];
|
|
24
24
|
/**
|
|
25
25
|
* Reverse op of {@link floatToIntBits64}.
|
|
26
26
|
*
|
|
27
|
-
* @param hi
|
|
28
|
-
* @param lo
|
|
27
|
+
* @param hi -
|
|
28
|
+
* @param lo -
|
|
29
29
|
*/
|
|
30
30
|
export declare const intBitsToFloat64: FnN2;
|
|
31
31
|
/**
|
|
32
32
|
* Reverse op of {@link floatToUintBits64}.
|
|
33
33
|
*
|
|
34
|
-
* @param hi
|
|
35
|
-
* @param lo
|
|
34
|
+
* @param hi -
|
|
35
|
+
* @param lo -
|
|
36
36
|
*/
|
|
37
37
|
export declare const uintBitsToFloat64: FnN2;
|
|
38
38
|
/**
|
|
@@ -48,49 +48,49 @@ export declare const floatToSortableInt: FnN;
|
|
|
48
48
|
/**
|
|
49
49
|
* Converts normalized float ([-1..1] range) to u8.
|
|
50
50
|
*
|
|
51
|
-
* @param x
|
|
51
|
+
* @param x -
|
|
52
52
|
*/
|
|
53
53
|
export declare const f32u8: FnN;
|
|
54
54
|
/**
|
|
55
55
|
* Converts normalized float ([-1..1] range) to u16.
|
|
56
56
|
*
|
|
57
|
-
* @param x
|
|
57
|
+
* @param x -
|
|
58
58
|
*/
|
|
59
59
|
export declare const f32u16: FnN;
|
|
60
60
|
/**
|
|
61
61
|
* Converts normalized float ([-1..1] range) to u24.
|
|
62
62
|
*
|
|
63
|
-
* @param x
|
|
63
|
+
* @param x -
|
|
64
64
|
*/
|
|
65
65
|
export declare const f32u24: FnN;
|
|
66
66
|
/**
|
|
67
67
|
* Converts normalized float ([-1..1] range) to u32.
|
|
68
68
|
*
|
|
69
|
-
* @param x
|
|
69
|
+
* @param x -
|
|
70
70
|
*/
|
|
71
71
|
export declare const f32u32: FnN;
|
|
72
72
|
/**
|
|
73
73
|
* Reverse op of {@link f32u8}.
|
|
74
74
|
*
|
|
75
|
-
* @param x
|
|
75
|
+
* @param x -
|
|
76
76
|
*/
|
|
77
77
|
export declare const u8f32: FnN;
|
|
78
78
|
/**
|
|
79
79
|
* Reverse op of {@link f32u16}.
|
|
80
80
|
*
|
|
81
|
-
* @param x
|
|
81
|
+
* @param x -
|
|
82
82
|
*/
|
|
83
83
|
export declare const u16f32: FnN;
|
|
84
84
|
/**
|
|
85
85
|
* Reverse op of {@link f32u24}.
|
|
86
86
|
*
|
|
87
|
-
* @param x
|
|
87
|
+
* @param x -
|
|
88
88
|
*/
|
|
89
89
|
export declare const u24f32: FnN;
|
|
90
90
|
/**
|
|
91
91
|
* Reverse op of {@link f32u32}.
|
|
92
92
|
*
|
|
93
|
-
* @param x
|
|
93
|
+
* @param x -
|
|
94
94
|
*/
|
|
95
95
|
export declare const u32f32: FnN;
|
|
96
96
|
//# sourceMappingURL=float.d.ts.map
|
package/float.js
CHANGED
|
@@ -14,21 +14,21 @@ export const uintBitsToFloat = (x) => ((U32[0] = x), F32[0]);
|
|
|
14
14
|
* Returns i32 representation of f64 as [hi, lo] tuple (takes
|
|
15
15
|
* environment's Little Endianess into account).
|
|
16
16
|
*
|
|
17
|
-
* @param x
|
|
17
|
+
* @param x -
|
|
18
18
|
*/
|
|
19
19
|
export const floatToIntBits64 = (x) => ((F64[0] = x), IS_LE ? [I32[1], I32[0]] : [I32[0], I32[1]]);
|
|
20
20
|
/**
|
|
21
21
|
* Returns u32 representation of f64 as [hi, lo] tuple (takes
|
|
22
22
|
* environment's Little Endianess into account).
|
|
23
23
|
*
|
|
24
|
-
* @param x
|
|
24
|
+
* @param x -
|
|
25
25
|
*/
|
|
26
26
|
export const floatToUintBits64 = (x) => ((F64[0] = x), IS_LE ? [U32[1], U32[0]] : [U32[0], U32[1]]);
|
|
27
27
|
/**
|
|
28
28
|
* Reverse op of {@link floatToIntBits64}.
|
|
29
29
|
*
|
|
30
|
-
* @param hi
|
|
31
|
-
* @param lo
|
|
30
|
+
* @param hi -
|
|
31
|
+
* @param lo -
|
|
32
32
|
*/
|
|
33
33
|
export const intBitsToFloat64 = (hi, lo) => {
|
|
34
34
|
IS_LE ? ((I32[1] = hi), (I32[0] = lo)) : ((I32[0] = hi), (I32[1] = lo));
|
|
@@ -37,8 +37,8 @@ export const intBitsToFloat64 = (hi, lo) => {
|
|
|
37
37
|
/**
|
|
38
38
|
* Reverse op of {@link floatToUintBits64}.
|
|
39
39
|
*
|
|
40
|
-
* @param hi
|
|
41
|
-
* @param lo
|
|
40
|
+
* @param hi -
|
|
41
|
+
* @param lo -
|
|
42
42
|
*/
|
|
43
43
|
export const uintBitsToFloat64 = (hi, lo) => {
|
|
44
44
|
IS_LE ? ((U32[1] = hi), (U32[0] = lo)) : ((U32[0] = hi), (U32[1] = lo));
|
|
@@ -63,48 +63,48 @@ const clamp11 = (x) => (x < -1 ? -1 : x > 1 ? 1 : x);
|
|
|
63
63
|
/**
|
|
64
64
|
* Converts normalized float ([-1..1] range) to u8.
|
|
65
65
|
*
|
|
66
|
-
* @param x
|
|
66
|
+
* @param x -
|
|
67
67
|
*/
|
|
68
68
|
export const f32u8 = (x) => (clamp11(x) * 0x7f) & 0xff;
|
|
69
69
|
/**
|
|
70
70
|
* Converts normalized float ([-1..1] range) to u16.
|
|
71
71
|
*
|
|
72
|
-
* @param x
|
|
72
|
+
* @param x -
|
|
73
73
|
*/
|
|
74
74
|
export const f32u16 = (x) => (clamp11(x) * 0x7fff) & 0xffff;
|
|
75
75
|
/**
|
|
76
76
|
* Converts normalized float ([-1..1] range) to u24.
|
|
77
77
|
*
|
|
78
|
-
* @param x
|
|
78
|
+
* @param x -
|
|
79
79
|
*/
|
|
80
80
|
export const f32u24 = (x) => (clamp11(x) * 0x7fffff) & 0xffffff;
|
|
81
81
|
/**
|
|
82
82
|
* Converts normalized float ([-1..1] range) to u32.
|
|
83
83
|
*
|
|
84
|
-
* @param x
|
|
84
|
+
* @param x -
|
|
85
85
|
*/
|
|
86
86
|
export const f32u32 = (x) => (clamp11(x) * 0x7fffffff) >>> 0;
|
|
87
87
|
/**
|
|
88
88
|
* Reverse op of {@link f32u8}.
|
|
89
89
|
*
|
|
90
|
-
* @param x
|
|
90
|
+
* @param x -
|
|
91
91
|
*/
|
|
92
92
|
export const u8f32 = (x) => ((x &= 0xff), (x | ((x >> 7) * 0xffffff00)) / 0x7f);
|
|
93
93
|
/**
|
|
94
94
|
* Reverse op of {@link f32u16}.
|
|
95
95
|
*
|
|
96
|
-
* @param x
|
|
96
|
+
* @param x -
|
|
97
97
|
*/
|
|
98
98
|
export const u16f32 = (x) => ((x &= 0xffff), (x | ((x >> 15) * 0xffff0000)) / 0x7fff);
|
|
99
99
|
/**
|
|
100
100
|
* Reverse op of {@link f32u24}.
|
|
101
101
|
*
|
|
102
|
-
* @param x
|
|
102
|
+
* @param x -
|
|
103
103
|
*/
|
|
104
104
|
export const u24f32 = (x) => ((x &= 0xffffff), (x | ((x >> 23) * 0xff000000)) / 0x7fffff);
|
|
105
105
|
/**
|
|
106
106
|
* Reverse op of {@link f32u32}.
|
|
107
107
|
*
|
|
108
|
-
* @param x
|
|
108
|
+
* @param x -
|
|
109
109
|
*/
|
|
110
110
|
export const u32f32 = (x) => (x | 0) / 0x7fffffff;
|
package/one-hot.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Range0_31 } from "@thi.ng/api";
|
|
|
5
5
|
* @remarks
|
|
6
6
|
* Reference: https://en.wikipedia.org/wiki/One-hot
|
|
7
7
|
*
|
|
8
|
-
* @param x
|
|
8
|
+
* @param x -
|
|
9
9
|
*/
|
|
10
10
|
export declare const binaryOneHot: (x: Range0_31) => number;
|
|
11
11
|
/**
|
|
@@ -14,7 +14,7 @@ export declare const binaryOneHot: (x: Range0_31) => number;
|
|
|
14
14
|
* @remarks
|
|
15
15
|
* Reference: https://en.wikipedia.org/wiki/One-hot
|
|
16
16
|
*
|
|
17
|
-
* @param x
|
|
17
|
+
* @param x -
|
|
18
18
|
*/
|
|
19
19
|
export declare const oneHotBinary: (x: number) => number;
|
|
20
20
|
//# sourceMappingURL=one-hot.d.ts.map
|
package/one-hot.js
CHANGED
|
@@ -5,7 +5,7 @@ import { clz32 } from "./count.js";
|
|
|
5
5
|
* @remarks
|
|
6
6
|
* Reference: https://en.wikipedia.org/wiki/One-hot
|
|
7
7
|
*
|
|
8
|
-
* @param x
|
|
8
|
+
* @param x -
|
|
9
9
|
*/
|
|
10
10
|
export const binaryOneHot = (x) => (1 << x) >>> 0;
|
|
11
11
|
/**
|
|
@@ -14,6 +14,6 @@ export const binaryOneHot = (x) => (1 << x) >>> 0;
|
|
|
14
14
|
* @remarks
|
|
15
15
|
* Reference: https://en.wikipedia.org/wiki/One-hot
|
|
16
16
|
*
|
|
17
|
-
* @param x
|
|
17
|
+
* @param x -
|
|
18
18
|
*/
|
|
19
19
|
export const oneHotBinary = (x) => 31 - clz32(x);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/binary",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "100+ assorted binary / bitwise operations, conversions, utilities, lookup tables",
|
|
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.
|
|
37
|
+
"@thi.ng/api": "^8.3.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/api-extractor": "^7.19.
|
|
41
|
-
"@thi.ng/testament": "^0.2.
|
|
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.
|
|
45
|
-
"typescript": "^4.
|
|
44
|
+
"typedoc": "^0.22.13",
|
|
45
|
+
"typescript": "^4.6.2"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
48
|
"align",
|
|
@@ -129,5 +129,5 @@
|
|
|
129
129
|
"transducers-binary"
|
|
130
130
|
]
|
|
131
131
|
},
|
|
132
|
-
"gitHead": "
|
|
132
|
+
"gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
|
|
133
133
|
}
|
package/rotate.d.ts
CHANGED
|
@@ -13,4 +13,12 @@ export declare const rotateLeft: (x: number, n: Bit) => number;
|
|
|
13
13
|
* @param n - rotation step
|
|
14
14
|
*/
|
|
15
15
|
export declare const rotateRight: (x: number, n: Bit) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Shifts `x` by `n` bits left or right. If `n` >= 0, the value will be `>>>`
|
|
18
|
+
* shifted to right, if `n` < 0 the value will be shifted left.
|
|
19
|
+
*
|
|
20
|
+
* @param x -
|
|
21
|
+
* @param n -
|
|
22
|
+
*/
|
|
23
|
+
export declare const shiftRL: (x: number, n: number) => number;
|
|
16
24
|
//# sourceMappingURL=rotate.d.ts.map
|
package/rotate.js
CHANGED
|
@@ -12,3 +12,11 @@ export const rotateLeft = (x, n) => ((x << n) | (x >>> (32 - n))) >>> 0;
|
|
|
12
12
|
* @param n - rotation step
|
|
13
13
|
*/
|
|
14
14
|
export const rotateRight = (x, n) => ((x >>> n) | (x << (32 - n))) >>> 0;
|
|
15
|
+
/**
|
|
16
|
+
* Shifts `x` by `n` bits left or right. If `n` >= 0, the value will be `>>>`
|
|
17
|
+
* shifted to right, if `n` < 0 the value will be shifted left.
|
|
18
|
+
*
|
|
19
|
+
* @param x -
|
|
20
|
+
* @param n -
|
|
21
|
+
*/
|
|
22
|
+
export const shiftRL = (x, n) => (n < 0 ? x << -n : x >>> n);
|
package/splat.d.ts
CHANGED
|
@@ -44,13 +44,13 @@ export declare const same8: (x: number) => boolean;
|
|
|
44
44
|
/**
|
|
45
45
|
* Expands 3x4bit value like `0xabc` to 24bits: `0xaabbcc`
|
|
46
46
|
*
|
|
47
|
-
* @param x
|
|
47
|
+
* @param x -
|
|
48
48
|
*/
|
|
49
49
|
export declare const interleave4_12_24: (x: number) => number;
|
|
50
50
|
/**
|
|
51
51
|
* Expands 4x4bit value like `0xabcd` to 32bits: `0xaabbccdd`
|
|
52
52
|
*
|
|
53
|
-
* @param x
|
|
53
|
+
* @param x -
|
|
54
54
|
*/
|
|
55
55
|
export declare const interleave4_16_32: (x: number) => number;
|
|
56
56
|
//# sourceMappingURL=splat.d.ts.map
|
package/splat.js
CHANGED
|
@@ -43,13 +43,13 @@ export const same8 = (x) => ((x >> 8) & 0xff) === (x & 0xff);
|
|
|
43
43
|
/**
|
|
44
44
|
* Expands 3x4bit value like `0xabc` to 24bits: `0xaabbcc`
|
|
45
45
|
*
|
|
46
|
-
* @param x
|
|
46
|
+
* @param x -
|
|
47
47
|
*/
|
|
48
48
|
export const interleave4_12_24 = (x) => ((x & 0xf00) * 0x1100) | ((x & 0xf0) * 0x110) | ((x & 0xf) * 0x11);
|
|
49
49
|
/**
|
|
50
50
|
* Expands 4x4bit value like `0xabcd` to 32bits: `0xaabbccdd`
|
|
51
51
|
*
|
|
52
|
-
* @param x
|
|
52
|
+
* @param x -
|
|
53
53
|
*/
|
|
54
54
|
export const interleave4_16_32 = (x) => (((x & 0xf000) * 0x11000) |
|
|
55
55
|
((x & 0xf00) * 0x1100) |
|
package/swizzle.d.ts
CHANGED
|
@@ -116,9 +116,9 @@ export declare const swizzle4: (x: number, a: Lane4, b: Lane4, c: Lane4, d: Lane
|
|
|
116
116
|
* // 0x12345555
|
|
117
117
|
* ```
|
|
118
118
|
*
|
|
119
|
-
* @param a
|
|
120
|
-
* @param b
|
|
121
|
-
* @param mask
|
|
119
|
+
* @param a -
|
|
120
|
+
* @param b -
|
|
121
|
+
* @param mask -
|
|
122
122
|
*/
|
|
123
123
|
export declare const mux: FnN3;
|
|
124
124
|
/**
|
|
@@ -136,7 +136,7 @@ export declare const flip8: FnN;
|
|
|
136
136
|
* // 0x56781234
|
|
137
137
|
* ```
|
|
138
138
|
*
|
|
139
|
-
* @param x
|
|
139
|
+
* @param x -
|
|
140
140
|
*/
|
|
141
141
|
export declare const flip16: FnN;
|
|
142
142
|
/**
|
|
@@ -146,13 +146,13 @@ export declare const flipBytes: FnN;
|
|
|
146
146
|
/**
|
|
147
147
|
* Swaps bytes lanes 0 & 2 (i.e. bits 24-31 with bits 8-15)
|
|
148
148
|
*
|
|
149
|
-
* @param x
|
|
149
|
+
* @param x -
|
|
150
150
|
*/
|
|
151
151
|
export declare const swapLane02: FnN;
|
|
152
152
|
/**
|
|
153
153
|
* Swaps bytes lanes 1 & 3 (i.e. bits 16-23 with bits 0-7)
|
|
154
154
|
*
|
|
155
|
-
* @param x
|
|
155
|
+
* @param x -
|
|
156
156
|
*/
|
|
157
157
|
export declare const swapLane13: FnN;
|
|
158
158
|
//# sourceMappingURL=swizzle.d.ts.map
|
package/swizzle.js
CHANGED
|
@@ -135,9 +135,9 @@ export const swizzle4 = (x, a, b, c, d, e, f, g, h) => ((lane4(x, a) << 28) |
|
|
|
135
135
|
* // 0x12345555
|
|
136
136
|
* ```
|
|
137
137
|
*
|
|
138
|
-
* @param a
|
|
139
|
-
* @param b
|
|
140
|
-
* @param mask
|
|
138
|
+
* @param a -
|
|
139
|
+
* @param b -
|
|
140
|
+
* @param mask -
|
|
141
141
|
*/
|
|
142
142
|
export const mux = (a, b, mask) => (~mask & a) | (mask & b);
|
|
143
143
|
/**
|
|
@@ -155,7 +155,7 @@ export const flip8 = (x) => ((x >>> 24) | ((x >> 8) & 0xff00) | ((x & 0xff00) <<
|
|
|
155
155
|
* // 0x56781234
|
|
156
156
|
* ```
|
|
157
157
|
*
|
|
158
|
-
* @param x
|
|
158
|
+
* @param x -
|
|
159
159
|
*/
|
|
160
160
|
export const flip16 = (x) => mux(x << 16, x >>> 16, 0xffff);
|
|
161
161
|
/**
|
|
@@ -165,12 +165,12 @@ export const flipBytes = flip8;
|
|
|
165
165
|
/**
|
|
166
166
|
* Swaps bytes lanes 0 & 2 (i.e. bits 24-31 with bits 8-15)
|
|
167
167
|
*
|
|
168
|
-
* @param x
|
|
168
|
+
* @param x -
|
|
169
169
|
*/
|
|
170
170
|
export const swapLane02 = (x) => ((x & 0xff00) << 16) | ((x >>> 16) & 0xff00) | (x & 0x00ff00ff);
|
|
171
171
|
/**
|
|
172
172
|
* Swaps bytes lanes 1 & 3 (i.e. bits 16-23 with bits 0-7)
|
|
173
173
|
*
|
|
174
|
-
* @param x
|
|
174
|
+
* @param x -
|
|
175
175
|
*/
|
|
176
176
|
export const swapLane13 = (x) => ((x & 0xff) << 16) | ((x >> 16) & 0xff) | (x & 0xff00ff00);
|