@thi.ng/dlogic 2.1.44 → 2.1.45
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 +1 -1
- package/README.md +1 -1
- package/index.js +59 -256
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,261 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* | 0 | 0 | 1 |
|
|
18
|
-
* | 0 | 1 | 1 |
|
|
19
|
-
* | 1 | 0 | 1 |
|
|
20
|
-
* | 1 | 1 | 0 |
|
|
21
|
-
*
|
|
22
|
-
* @param a -
|
|
23
|
-
* @param b -
|
|
24
|
-
*/
|
|
25
|
-
export const nand = (a, b) => !(a && b);
|
|
26
|
-
/**
|
|
27
|
-
* https://en.wikipedia.org/wiki/AND_gate
|
|
28
|
-
*
|
|
29
|
-
* | A | B | Q |
|
|
30
|
-
* |---|---|---|
|
|
31
|
-
* | 0 | 0 | 0 |
|
|
32
|
-
* | 0 | 1 | 0 |
|
|
33
|
-
* | 1 | 0 | 0 |
|
|
34
|
-
* | 1 | 1 | 1 |
|
|
35
|
-
*
|
|
36
|
-
* @param a -
|
|
37
|
-
* @param b -
|
|
38
|
-
*/
|
|
39
|
-
export const and = (a, b) => a && b;
|
|
40
|
-
/**
|
|
41
|
-
* https://en.wikipedia.org/wiki/OR_gate
|
|
42
|
-
*
|
|
43
|
-
* | A | B | Q |
|
|
44
|
-
* |---|---|---|
|
|
45
|
-
* | 0 | 0 | 0 |
|
|
46
|
-
* | 0 | 1 | 1 |
|
|
47
|
-
* | 1 | 0 | 1 |
|
|
48
|
-
* | 1 | 1 | 1 |
|
|
49
|
-
*
|
|
50
|
-
* @param a -
|
|
51
|
-
* @param b -
|
|
52
|
-
*/
|
|
53
|
-
export const or = (a, b) => a || b;
|
|
54
|
-
/**
|
|
55
|
-
* https://en.wikipedia.org/wiki/NOR_gate
|
|
56
|
-
*
|
|
57
|
-
* | A | B | Q |
|
|
58
|
-
* |---|---|---|
|
|
59
|
-
* | 0 | 0 | 1 |
|
|
60
|
-
* | 0 | 1 | 0 |
|
|
61
|
-
* | 1 | 0 | 0 |
|
|
62
|
-
* | 1 | 1 | 0 |
|
|
63
|
-
*
|
|
64
|
-
* @param a -
|
|
65
|
-
* @param b -
|
|
66
|
-
*/
|
|
67
|
-
export const nor = (a, b) => !(a || b);
|
|
68
|
-
/**
|
|
69
|
-
* https://en.wikipedia.org/wiki/XOR_gate
|
|
70
|
-
*
|
|
71
|
-
* | A | B | Q |
|
|
72
|
-
* |---|---|---|
|
|
73
|
-
* | 0 | 0 | 0 |
|
|
74
|
-
* | 0 | 1 | 1 |
|
|
75
|
-
* | 1 | 0 | 1 |
|
|
76
|
-
* | 1 | 1 | 0 |
|
|
77
|
-
*
|
|
78
|
-
* @param a -
|
|
79
|
-
* @param b -
|
|
80
|
-
*/
|
|
81
|
-
export const xor = (a, b) => a !== b;
|
|
82
|
-
/**
|
|
83
|
-
* https://en.wikipedia.org/wiki/XNOR_gate
|
|
84
|
-
*
|
|
85
|
-
* | A | B | Q |
|
|
86
|
-
* |---|---|---|
|
|
87
|
-
* | 0 | 0 | 1 |
|
|
88
|
-
* | 0 | 1 | 0 |
|
|
89
|
-
* | 1 | 0 | 0 |
|
|
90
|
-
* | 1 | 1 | 1 |
|
|
91
|
-
*
|
|
92
|
-
* @param a -
|
|
93
|
-
* @param b -
|
|
94
|
-
*/
|
|
95
|
-
export const xnor = (a, b) => a === b;
|
|
96
|
-
/**
|
|
97
|
-
* https://web.archive.org/web/20160304050642/http://www.zigwap.com/digital/gates/imply_gate
|
|
98
|
-
*
|
|
99
|
-
* | A | B | Q |
|
|
100
|
-
* |---|---|---|
|
|
101
|
-
* | 0 | 0 | 1 |
|
|
102
|
-
* | 0 | 1 | 1 |
|
|
103
|
-
* | 1 | 0 | 0 |
|
|
104
|
-
* | 1 | 1 | 1 |
|
|
105
|
-
* @param a -
|
|
106
|
-
* @param b -
|
|
107
|
-
*/
|
|
108
|
-
export const imply = (a, b) => !a || b;
|
|
109
|
-
/**
|
|
110
|
-
* https://en.wikipedia.org/wiki/AND-OR-Invert
|
|
111
|
-
*
|
|
112
|
-
* `q = nor(a, and(b, c))`
|
|
113
|
-
*
|
|
114
|
-
* | A | B | C | Q |
|
|
115
|
-
* |---|---|---|---|
|
|
116
|
-
* | 0 | 0 | 0 | 1 |
|
|
117
|
-
* | 0 | 0 | 1 | 1 |
|
|
118
|
-
* | 0 | 1 | 0 | 1 |
|
|
119
|
-
* | 0 | 1 | 1 | 0 |
|
|
120
|
-
* | 1 | 0 | 0 | 0 |
|
|
121
|
-
* | 1 | 0 | 1 | 0 |
|
|
122
|
-
* | 1 | 1 | 0 | 0 |
|
|
123
|
-
* | 1 | 1 | 1 | 0 |
|
|
124
|
-
*
|
|
125
|
-
* @param a -
|
|
126
|
-
* @param b -
|
|
127
|
-
* @param c -
|
|
128
|
-
*/
|
|
129
|
-
export const aoi21 = (a, b, c) => !(a || (b && c));
|
|
130
|
-
/**
|
|
131
|
-
* https://en.wikipedia.org/wiki/AND-OR-Invert
|
|
132
|
-
*
|
|
133
|
-
* `q = nor(and(a, b), and(c, d))`
|
|
134
|
-
*
|
|
135
|
-
* | A | B | C | D | Q |
|
|
136
|
-
* |---|---|---|---|---|
|
|
137
|
-
* | 0 | X | X | 0 | 1 |
|
|
138
|
-
* | X | 0 | X | 0 | 1 |
|
|
139
|
-
* | 0 | X | 0 | X | 1 |
|
|
140
|
-
* | X | 0 | 0 | X | 1 |
|
|
141
|
-
* | 1 | 1 | X | X | 0 |
|
|
142
|
-
* | X | X | 1 | 1 | 0 |
|
|
143
|
-
*
|
|
144
|
-
* @param a -
|
|
145
|
-
* @param b -
|
|
146
|
-
* @param c -
|
|
147
|
-
*/
|
|
148
|
-
export const aoi22 = (a, b, c, d) => !((a && b) || (c && d));
|
|
149
|
-
/**
|
|
150
|
-
* Complement logic of {@link aoi21}.
|
|
151
|
-
*
|
|
152
|
-
* `q = nand(a, or(b, c))`
|
|
153
|
-
*
|
|
154
|
-
* @param a -
|
|
155
|
-
* @param b -
|
|
156
|
-
* @param c -
|
|
157
|
-
*/
|
|
158
|
-
export const oai21 = (a, b, c) => !(a && (b || c));
|
|
159
|
-
/**
|
|
160
|
-
* Complement logic of {@link aoi22}.
|
|
161
|
-
*
|
|
162
|
-
* `q = nand(or(a, b), or(c, d))`
|
|
163
|
-
*
|
|
164
|
-
* @param a -
|
|
165
|
-
* @param b -
|
|
166
|
-
* @param c -
|
|
167
|
-
* @param d -
|
|
168
|
-
*/
|
|
169
|
-
export const oai22 = (a, b, c, d) => !((a || b) && (c || d));
|
|
170
|
-
/**
|
|
171
|
-
* https://en.wikipedia.org/wiki/NAND_logic#MUX
|
|
172
|
-
*
|
|
173
|
-
* | A | B | S | Q |
|
|
174
|
-
* |---|---|---|---|
|
|
175
|
-
* | 0 | 0 | 0 | 0 |
|
|
176
|
-
* | 0 | 1 | 0 | 0 |
|
|
177
|
-
* | 1 | 0 | 0 | 1 |
|
|
178
|
-
* | 1 | 1 | 0 | 1 |
|
|
179
|
-
* | 0 | 0 | 1 | 0 |
|
|
180
|
-
* | 0 | 1 | 1 | 1 |
|
|
181
|
-
* | 1 | 0 | 1 | 0 |
|
|
182
|
-
* | 1 | 1 | 1 | 1 |
|
|
183
|
-
*
|
|
184
|
-
* @param a -
|
|
185
|
-
* @param b -
|
|
186
|
-
* @param s -
|
|
187
|
-
*/
|
|
188
|
-
export const mux = (a, b, s) => (a && !s) || (b && s);
|
|
189
|
-
/**
|
|
190
|
-
* https://en.wikipedia.org/wiki/NAND_logic#DEMUX
|
|
191
|
-
*
|
|
192
|
-
* | I | S | A | B |
|
|
193
|
-
* |---|---|---|---|
|
|
194
|
-
* | 0 | 0 | 0 | 0 |
|
|
195
|
-
* | 1 | 0 | 1 | 0 |
|
|
196
|
-
* | 0 | 1 | 0 | 0 |
|
|
197
|
-
* | 1 | 1 | 0 | 1 |
|
|
198
|
-
*
|
|
199
|
-
* @param i -
|
|
200
|
-
* @param s -
|
|
201
|
-
*/
|
|
202
|
-
export const demux = (i, s) => [
|
|
203
|
-
i && !s,
|
|
204
|
-
i && s,
|
|
1
|
+
const not = (x) => !x;
|
|
2
|
+
const nand = (a, b) => !(a && b);
|
|
3
|
+
const and = (a, b) => a && b;
|
|
4
|
+
const or = (a, b) => a || b;
|
|
5
|
+
const nor = (a, b) => !(a || b);
|
|
6
|
+
const xor = (a, b) => a !== b;
|
|
7
|
+
const xnor = (a, b) => a === b;
|
|
8
|
+
const imply = (a, b) => !a || b;
|
|
9
|
+
const aoi21 = (a, b, c) => !(a || b && c);
|
|
10
|
+
const aoi22 = (a, b, c, d) => !(a && b || c && d);
|
|
11
|
+
const oai21 = (a, b, c) => !(a && (b || c));
|
|
12
|
+
const oai22 = (a, b, c, d) => !((a || b) && (c || d));
|
|
13
|
+
const mux = (a, b, s) => a && !s || b && s;
|
|
14
|
+
const demux = (i, s) => [
|
|
15
|
+
i && !s,
|
|
16
|
+
i && s
|
|
205
17
|
];
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
* @param a -
|
|
210
|
-
* @param b -
|
|
211
|
-
*/
|
|
212
|
-
export const hadd1 = (a, b) => ({
|
|
213
|
-
s: a !== b,
|
|
214
|
-
c: a && b,
|
|
18
|
+
const hadd1 = (a, b) => ({
|
|
19
|
+
s: a !== b,
|
|
20
|
+
c: a && b
|
|
215
21
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* @param a -
|
|
220
|
-
* @param b -
|
|
221
|
-
* @param c -
|
|
222
|
-
*/
|
|
223
|
-
export const fadd1 = (a, b, c) => ({
|
|
224
|
-
s: (a !== b) !== c,
|
|
225
|
-
c: (a !== b && c) || (a && b),
|
|
22
|
+
const fadd1 = (a, b, c) => ({
|
|
23
|
+
s: a !== b !== c,
|
|
24
|
+
c: a !== b && c || a && b
|
|
226
25
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const s = [];
|
|
236
|
-
for (let n = a.length, i = 0; i < n; i++) {
|
|
237
|
-
const r = fadd1(a[i], b[i], c);
|
|
238
|
-
s.push(r.s);
|
|
239
|
-
c = r.c;
|
|
240
|
-
}
|
|
241
|
-
return { s, c };
|
|
26
|
+
const rca = (a, b, c) => {
|
|
27
|
+
const s = [];
|
|
28
|
+
for (let n = a.length, i = 0; i < n; i++) {
|
|
29
|
+
const r = fadd1(a[i], b[i], c);
|
|
30
|
+
s.push(r.s);
|
|
31
|
+
c = r.c;
|
|
32
|
+
}
|
|
33
|
+
return { s, c };
|
|
242
34
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
35
|
+
const delay = (n) => {
|
|
36
|
+
const buf = new Array(n).fill(false);
|
|
37
|
+
let i = 0;
|
|
38
|
+
return n > 0 ? (x) => {
|
|
39
|
+
const y = buf[i];
|
|
40
|
+
buf[i++] = x;
|
|
41
|
+
i %= n;
|
|
42
|
+
return y;
|
|
43
|
+
} : (x) => x;
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
and,
|
|
47
|
+
aoi21,
|
|
48
|
+
aoi22,
|
|
49
|
+
delay,
|
|
50
|
+
demux,
|
|
51
|
+
fadd1,
|
|
52
|
+
hadd1,
|
|
53
|
+
imply,
|
|
54
|
+
mux,
|
|
55
|
+
nand,
|
|
56
|
+
nor,
|
|
57
|
+
not,
|
|
58
|
+
oai21,
|
|
59
|
+
oai22,
|
|
60
|
+
or,
|
|
61
|
+
rca,
|
|
62
|
+
xnor,
|
|
63
|
+
xor
|
|
261
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/dlogic",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.45",
|
|
4
4
|
"description": "Assorted digital logic ops / constructs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,10 +35,11 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
38
|
+
"@thi.ng/api": "^8.9.12"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@microsoft/api-extractor": "^7.38.3",
|
|
42
|
+
"esbuild": "^0.19.8",
|
|
40
43
|
"rimraf": "^5.0.5",
|
|
41
44
|
"tools": "^0.0.1",
|
|
42
45
|
"typedoc": "^0.25.4",
|
|
@@ -68,5 +71,5 @@
|
|
|
68
71
|
"thi.ng": {
|
|
69
72
|
"year": 2017
|
|
70
73
|
},
|
|
71
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
72
75
|
}
|