-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperescalar.js
728 lines (653 loc) · 23.5 KB
/
Superescalar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
'use strict';
import {WebSystemObject} from './WebSystemObject.js';
import {SimpleParse} from './Parse';
// Clase para representar números enteros extremadamente grandes (naturales no negativos),
// implementación del Teorema fundamental de la aritmética, en lenguaje OOP de Javascript.
export class SuperScalar extends WebSystemObject {
static Thread = class {
// alive tasks ids (not by names)
static tasks = [];
// valid instructions (luego incluye la ayuda, parámetros y extensibilidad).
static validInstructions = ['ADD', 'SUB', 'MUL', 'DIV', 'LOAD', 'POW', 'ROOT', 'STORE', 'BRANCH'];
constructor(func, paralell = SuperScalar.multitasking) {
let blob;
if (func instanceof Function) {
blob = new Blob([`(${func.toString()})()`], {type: 'application/javascript'});
const url = URL.createObjectURL(blob);
this.worker = new Worker(url);
this.worker.onmessage = (event) => {
if (this.onmessage) {
this.onmessage(event.data);
}
};
URL.revokeObjectURL(url);
} else {
this.onmessage(Thread.procesarMensaje(func, 0));
}
}
static procesarMensaje(instructions, initialAccumulator = 0) {
let enqueue = [];
let result = initialAccumulator;
for (let i = 0; i < instructions.length(); i++) {
let parseo = new SimpleParse();
let resultado = parseo.parsear();
if (resultado.length > 0) {
switch (SuperScalar.Task.validInstructions.some(String(resultado[0].op).toLocaleUpperCase())) {
case 'ADD': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#coreAdd(result, resultado.resultado[0].args[1]);
break;
}
case 'SUB': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#coreSubtract(result, resultado.resultado[0].args[1]);
break;
}
case 'MUL': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#coreMultiply(resultado.resultado[0].args[0], resultado.resultado[0].args[1]);
break;
}
case 'DIV': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#coreDivide(resultado.resultado[0].args[0], resultado.resultado[0].args[1]);
break;
}
case 'ROOT': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#coreRoot(resultado.resultado[0].args[0], resultado.resultado[0].args[1]);
break;
}
case 'POW': {
result = resultado.resultado[0].args[0];
result = SuperScalar.#corePow(resultado.resultado[0].args[0], resultado.resultado[0].args[1]);
break;
}
case 'LOAD': {
result = resultado.resultado[0].args[0];
break;
}
case 'STORE': {
result = tal; // ¿?
break;
}
}
}
}
return result;
};
postMessage(message) {
this.worker.postMessage(message);
}
set onmessage(handler) {
this._onmessage = handler;
}
get onmessage() {
return this._onmessage;
}
async getResults(code) {
return new Promise((resolve, reject) => {
this.onmessage = (result) => {
resolve(result);
};
this.postMessage(code);
});
}
// Evaluación paralela de código en otro hilo
// awaqit this.calculateResult('2 + 2'); // Imprime "4" en la consola (solo crea el Thread)
async calculateResult(code) {
return new Promise((resolve, reject) => {
this.onmessage = (result) => {
resolve(result);
};
this.postMessage(code);
});
}
};
// this privates inheritances for polymorphic internal use only...
static #ScalarZero = class extends SuperScalar {
constructor() {
super(null, true);
}
toString() {
return '0';
}
};
static #ScalarPrime = class extends SuperScalar {
constructor(index) {
super({index}, true);
}
toString() {
return this.primeValue(this.stru.index).toString();
}
};
static #ScalarFactor = class extends SuperScalar { // 1 is considered
constructor({base, exponent}) {
const baseLikeMe = base instanceof SuperScalar ? base : new SuperScalar(base);
const exponentLikeMe = exponent instanceof SuperScalar ? exponent : new SuperScalar(exponent);
if (baseLikeMe instanceof SuperScalar.#ScalarZero) {
new SuperScalar.#ScalarZero();
} else { // incluir lo que pasa cuando la base es 1... o es un número primo de exponente 1, se crean dos cosas diferentes...
super({base: baseLikeMe, exponent: exponentLikeMe});
}
}
toString() {
return this.strPow(this.primeValue(this.stru.base), this.stru.exponent).toString();
}
};
static #ScalarProduct = class extends SuperScalar {
// Arreglo de factores, el índice del primero es absoluto, los demás...
constructor(factors) {
super(...factors);
// Lo anterior guarda la estructura de factores en stru,
// (que a propósito, creo que es innecesaria: debido al polimorfismo
// probablemente no se necesiten otros datos que el tipo de objeto,
// lo que pasa con la clase 0, pero para demostrar eso primero tengo que terminar),
// el próximo paso es optimizar, recuerda el primer índice es absoluto
// y los consecuentes, relativos a los precedentes
// el 1 (uno), normalmente se representa 2^0, y
// el dos se representa 2^1 (ambos se expresan como potencias de dos)
// pero eso solamente lo utilizamos para el dos, para los otros números
// primos, desactivamos esta posibilidad, con el fin de evitar redundancias
// se asume que todas las potencias comienzan en 1...
// al optimizarse, solamente el primer número es el índice de un número
// primo, los subsiguientes ni siquiera son índices de ellos (primos) sino
// que constituyen diferencias relativas, donde 0, desde luego significa
// el siguiente número primo de la criba, pd ds.
// Esto es solamente para las bases, los exponentes de cada factor se
// codifican normalmente y no se les aplica tal relativización.
}
toString() {
let product = '1';
let previousPrimeIndex = 0n;
this.stru.factors.forEach((fac) => {
product = this.strMultiply(product, this.strPow(this.primeValue(this.strAdd(previousPrimeIndex, fac.base)), fac.exponent));
previousPrimeIndex = this.strSubtract(fac.base, previousPrimeIndex);
});
return product;
}
};
static #ScalarInfinity = class extends SuperScalar.#ScalarProduct {
constructor() {
super([]);
}
toString() {
return '∞';
}
};
static #ScalarUndefined = class extends SuperScalar {
constructor() {
super();
}
toString() {
return 'undefined';
}
};
// https://oeis.org/A007053/b007053.txt
static mersennesPrimesIndexes = ['1', '2', '4', '6', '11', '18', '31', '54', '97', '172', '309', '564', '1028', '1900', '3512', '6542', '12251', '23000', '43390', '82025', '155611', '295947', '564163', '1077871', '2063689', '3957809', '7603553', '14630843', '28192750', '54400028', '105097565', '203280221', '393615806', '762939111', '1480206279', '2874398515', '5586502348', '10866266172', '21151907950', '41203088796', '80316571436', '156661034233', '305761713237', '597116381732', '1166746786182', '2280998753949', '4461632979717', '8731188863470', '17094432576778', '33483379603407', '65612899915304', '128625503610475', '252252704148404', '494890204904784', '971269945245201', '1906879381028850', '3745011184713964', '7357400267843990', '14458792895301660', '28423094496953330', '55890484045084135', '109932807585469973', '216289611853439384', '425656284035217743', '837903145466607212', '1649819700464785589', '3249254387052557215', '6400771597544937806', '12611864618760352880', '24855455363362685793', '48995571600129458363', '96601075195075186855', '190499823401327905601', '375744164937699609596', '741263521140740113483', '1462626667154509638735', '2886507381056867953916', '5697549648954257752872', '11248065615133675809379', '22209558889635384205844', '43860397052947409356492', '86631124695994360074872', '171136408646923240987028', '338124238545210097236684', '668150111666935905701562', '1320486952377516565496055', '2610087356951889016077639', '5159830247726102115466054', '10201730804263125133012340', '20172933541156002700963336', '39895115987049029184882256', '78908656317357166866404346'];
// some Mersenne numbers (the two exponent) from 1 to 50
static mersennes = ['2', '3', '5', '7', '13', '17', '19', '31', '61', '89', '107', '127', '521', '607', '1279', '2203', '2281', '3217', '4253', '4423', '9689', '9941', '11213', '19937', '21701', '23209', '44497', '86243', '110503', '132049', '216091', '756839', '859433', '1257787', '1398269', '2976221', '3021377', '6972593', '13466917', '20996011', '24036583', '25964951', '30402457', '32582657', '37156667', '42643801', '43112609', '57885161', '74207281', '77232917'];
static multitasking = true;
static tasks = [];
constructor(definition, multitasking = true) {
super();
SuperScalar.multitasking = multitasking;
if (definition) {
if (definition instanceof SuperScalar) {
this.stru = definition.stru; // Acepta un Number, BigInteger o objeto Scalar.
} else if (definition instanceof Number || definition instanceof BigInt) {
if (BigInt(definition) === 0n) {
new SuperScalar.#ScalarZero();
} else if (this.primality(definition)) {
const primeIndex = this.primeIndex(definition);
new SuperScalar.#ScalarPrime(primeIndex);
} else {
const factorFields = this.group(this.primeFactors(definition));
if (factorFields.length === 1) {
new SuperScalar.#ScalarFactor(factorFields[0]);
} else {
new SuperScalar.#ScalarProduct(factorFields);
}
}
} else if (definition instanceof String || typeof definition === 'string') {
if (definition[0] === '+') { // supress preceding sign & reconstruct all again
new SuperScalar(definition.substr(1).trim);
}
if (this.potable(definition).success) {
new SuperScalar(Number(definition));
} else if (definition instanceof BigInt) {
new SuperScalar(BigInt(definition));
} else if (definition.trim() === '∞' || definition.trim() === 'Infinity') {
new SuperScalar.#ScalarInfinity();
}
} else if (definition.toString() === '0') {
new SuperScalar.#ScalarZero();
}
}
}
addTask(name, fn) {
const task = new SuperScalar.Task(name, fn);
SuperScalar.Task.tasks.push(task);
}
async executeTasks(workers = false) {
let promises;
if (workers) {
const promises = SuperScalar.Task.tasks.map(task => task.getResult());
} else {
const promises = SuperScalar.Task.tasks.map(task => task.execute());
await Promise.allSettled(promises);
}
return promises;
}
isZero(definition) {
const likeMe = definition instanceof SuperScalar ? definition : new SuperScalar(definition);
return likeMe instanceof SuperScalar.#ScalarZero;
}
isPrime(definition) { // 2 is considered prime number 0
const likeMe = definition instanceof SuperScalar ? definition : new SuperScalar(definition);
return likeMe instanceof SuperScalar.#ScalarPrime;
}
// Pueden crearse clases auxiliares para representar números en forma de sumas, diferencias o
// factoriales sin evaluar... especialmente cuando se dificulte la factorización.
isProduct(definition) { // Todos excepto 0, 1, y los números primos (∞ siempre se considera).
const likeMe = definition instanceof SuperScalar ? definition : new SuperScalar(definition);
return likeMe instanceof SuperScalar.#ScalarProduct;
}
// Primitives
isInfinity(definition) { // 2 is considered prime number 0
const likeMe = definition instanceof SuperScalar ? definition : new SuperScalar(definition);
return likeMe instanceof SuperScalar.#ScalarInfinity;
}
// Euler's Pi function optimize later (test it please)
#subPrimeIndex(to, from = 0n) {
const deep = BigInt(to.toString());
let point = BigInt(from.toString());
let count = 0n;
const step = from <= to ? 1n : -1n;
while (step > 0 ? point <= deep : point >= deep) {
if (this.primality(point)) {
count = count + 1n;
}
point = point + step;
}
return step * count;
}
primeIndex(value) {
const deep = BigInt(value);
// Distancia que podemos recorrar localizando un primo desde uno conocido
const carrier = 10000;
let result;
if (deep < carrier) {
result = this.#subPrimeIndex(deep);
} else {
// Tratar de encontrar el índice por cercanía,
// si no está lo suficientemente cerca, utiliza la función Li,
// o lo mejor que tengas, no hay de otra.
result = this.#subPrimeIndex(0, deep.value);
}
return result;
}
// modpow
modpow(baseP, expP, mP) {
let base = BigInt(baseP);
let exp = BigInt(expP);
const m = BigInt(mP);
if (m === 1n) return 0n;
if (exp === 0n) return 1n;
if (base === 0n) return 0n;
if (((base < 10n) && (exp < 10n) && (m < 10n)) || (exp < 1n)) {
return BigInt(this.strPow(base, exp)) % m;
}
while (exp >= 2n && exp % 2n === 0n) {
exp /= 2n;
base = BigInt(this.strPow(base, 2n));
}
while (exp >= 3n && exp % 3n === 0n) {
exp /= 3n;
base = BigInt(this.strPow(base, 3n));
}
while (exp >= 5n && exp % 5n === 0n) {
exp /= 5n;
base = BigInt(this.strPow(base, 5n));
}
if (exp > 1000n) {
const r = BigInt(this.strRoot(2n, exp));
return this.modpow(this.modpow(base, r, m), r, m);
}
return ((base * this.modpow(base, exp - 1n, m))) % m;
}
// Función gamma (recursiva sin optimizar).
#gamma(n) {
const x = BigInt(n);
switch (x) {
case 0n:
return 1n;
case 1n:
return 1n;
case 2n:
return 1n;
default:
return (x - 1n) * this.#gamma(x - 2n);
}
}
// Función "resto" de la división [(base^exp) ± d] mod m
#modpowplus(base, exp, d, m) {
return (m + this.modpow(base, exp, m) + d) % m; // m added to > 0 results.
}
gcd(aP, bP) {
function min(x, y) {
if (x < y) return x; else return y;
}
function max(x, y) {
if (x > y) return x; else return y;
}
const a = BigInt(aP);
const b = BigInt(bP);
let result;
let [minFactor, maxFactor] = [min(a, b), max(a, b)];
// this trivial checks avoids div. by zero.
if (minFactor === 0n) {
if (maxFactor === 0n) {
result = Infinity;
} else {
result = maxFactor;
}
} else if (maxFactor === 0n) {
if (minFactor === 0n) {
result = Infinity;
} else {
result = minFactor;
}
} else {
result = maxFactor;
while (minFactor !== 0n) {
maxFactor = result;
result = minFactor;
minFactor = maxFactor % minFactor;
}
}
return result;
}
// función "resto" de la división GCD( [(base^exp) ± d] mod m, p)
// Útil para factorizar números muy grandes
#gcdModPowPlus(base, exp, d, m, p) {
const tmp = this.#modpowplus(base, exp, d, m) % p;
return this.gcd(tmp, p);
}
// big factor 16/02/2003 (Big factorizer).
bigFac(n) {
const deep = BigInt(n);
let result = 0n;
if (deep < 3n) {
result = deep;
} else if (deep % 2n === 0n) {
result = 2n;
} else if (deep % 3n === 0n) {
result = 3n;
} else {
let d = deep;
let u = deep + 1;
const r = BigInt(this.strRoot(2n, deep));
if (deep % r === 0n) {
return r;
}
while (d > 1n) {
result = this.gcd(deep, deep - (this.modpow(r, d, deep) + 1n));
if (result !== 1n && result !== deep) return result;
result = this.gcd(deep, deep - (this.modpow(r, d, deep) - 1n));
if (result !== 1n && result !== deep) return result;
// sección 1
if (d <= 1n) {
result = deep;
break;
} else if (d % 2n === 0n) {
d = d / 2n;
} else {
d = d - 1n;
}
// sección 2
if (u <= 1n || u === d) {
continue;
} else if (u % 2n === 0n) {
u = u / 2n;
} else {
u = u + 1n;
}
result = this.gcd(deep, deep - (this.modpow(r, u, deep) + 1n));
if (result !== 1n && result !== deep) return result;
result = this.gcd(deep, deep - (this.modpow(r, u, deep) - 1n));
if (result !== 1n && result !== deep) return result;
}
}
return result;
}
// Hipótesis china
hch(n) {
return n % 2n !== 0 && this.modpow(2n, n, n) === 2n;
}
// Pequeño teorema de Fermat
ptf(n, base = 2n) {
return n % 2n !== 0 && this.modpow(base, n - 1n, n) === 1n;
}
// Teorema de Wilson (is BigInt, pls use 0n, 2n, 3n,... instead of 0, 1, 2, 3).
tw(n) {
return this.#gamma(n - 1n) % n === 1n;
}
primality(n) { // ok
const deep = BigInt(n.toString());
if (deep < 2n) return false;
if (deep === 2n || deep === 3n || deep === 5n) {
return true;
}
if (deep % 2n === 0n || deep % 3n === 0n || deep % 5n === 0n) {
return false;
}
for (let i = 7n; i < BigInt(this.strRoot(2n, deep.toString())); i = i + 1n) {
if (deep % i === 0n) {
return false;
}
}
return true;
}
primeValue(index) {
const deep = BigInt(index.toString());
let result = 0n; // brutal for now
let value = 2n;
while (result < deep) {
result++;
while (!this.primality(value)) {
value++;
}
}
return value;
}
isFactor(definition) {
const likeMe = definition instanceof SuperScalar ? definition : new SuperScalar(definition);
return likeMe instanceof SuperScalar.#ScalarFactor;
}
// fix
factorsFields(n, previousIndex = 0) { // lets go
const deep = BigInt(String(n));
const facs = this.group(this.primeFactors(deep));
let previous = 0;
return facs.map((element, index, arr) => {
const newIndex = this.strSubtract(this.primeIndex(element.factor), previous);
previous = newIndex;
return {
factor: new SuperScalar.#ScalarPrime(newIndex),
exponent: new SuperScalar(element.exponent),
};
});
}
group(array) {
let groupedResult = array.reduce((previous, current) => {
if (!previous[current]) previous[current] = [];
previous[current].push(current);
return previous;
}, []);
groupedResult = groupedResult.sort((a, b) => a - b).filter((defined) => defined);
groupedResult = groupedResult.map((factors) => {
return {factor: factors[0], exponent: factors.length};
});
return groupedResult;
}
primeFactors(n) { // ok
let deep = BigInt(n.toString());
const factors = [];
if (deep === 0n) {
return [];
} else if (deep === 1n) {
return [2n];
} else if (deep === 2n || deep === 3n || deep === 5n) {
return [deep];
}
let divisor = 2n;
const root = BigInt(this.strRoot(2, deep)) + 2n; // tentative limit
while (divisor < root) {
while (deep % divisor === 0n) {
factors.push(divisor);
deep = deep / divisor;
}
divisor++;
}
if (factors.length === 0) {
factors.push(deep);
}
return factors;
}
potable(definition = '') {
const deep = definition.toString();
const MAX_INT = String(9007199254740992);
const result = {success: true, value: undefined};
try {
result.value = BigInt(Math.trunc(Number(deep)));
result.success = BigInt(result.value) <= BigInt(MAX_INT);
} catch (e) {
result.success = false;
}
result.success = result.success && (String(deep).trim() === String(result.value).trim());
return result;
}
static #coreAdd(str1, str2) {
return (BigInt(str1.toString()) + BigInt(str2.toString())).toString();
}
static #coreSubtract(str1, str2) {
return (BigInt(str1.toString()) - BigInt(str2.toString())).toString();
}
// Multiplies two stringifisable factors whatever they are, and return result.
static #coreMultiply(str1, str2) {
return (BigInt(str1.toString()) * BigInt(str2.toString())).toString();
}
// By the way (str1 by str2)
static #coreDivide(str1, str2) {
return (BigInt(str1.toString()) / BigInt(str2.toString())).toString();
}
// Raise the base at the power of exponent
static #corePow(base, exponent) {
// just work with strings (again)
const bigBase = BigInt(String(base));
const bigExponent = BigInt(String(exponent));
let result;
if (bigBase === 0n) {
return '0';
}
if (bigBase === 1n) {
result = '1';
} else if (bigExponent === 2n) {
result = bigBase * bigBase;
} else if (bigExponent === 1n) {
result = bigBase;
} else if (bigExponent === 0n) {
result = '1';
} else if (bigExponent % 2n === 0n) {
result = this.strPow(bigBase, bigExponent / 2n);
} else {
result = bigBase * BigInt(SuperScalar.#corePow(bigBase, bigExponent - 1n));
}
return String(result);
}
static #coreRoot(root, value) {
let result;
const base = BigInt(String(value));
const r = BigInt(String(root));
let s = BigInt(base + 1n);
const k1 = BigInt(r - 1n);
let u = BigInt(base);
while (u < s) {
s = u;
u = ((u * k1) + base / BigInt(SuperScalar.strPow(u, k1))) / r;
}
result = s;
return result.toString();
}
strAdd(str1, str2) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${str1}`);
this.addTask('', `ADD ${str2}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#coreAdd(str1, str2);
}
return result;
}
strSubtract(str1, str2) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${str1}`);
this.addTask('', `SUB ${str2}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#coreSubtract(str1, str2);
}
return result;
}
// Multiplies two stringifisable factors whatever they are, and return result.
strMultiply(str1, str2) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${str1}`);
this.addTask('', `MUL ${str2}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#coreMultiply(str1, str2);
}
return result;
}
// By the way (str1 by str2)
strDivide(str1, str2) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${str1}`);
this.addTask('', `DIV ${str2}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#coreDivide(str1, str2);
}
return result;
}
// Enesimal root of value
strRoot(root, value) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${root}`);
this.addTask('', `ROOT ${value}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#coreRoot(str1, str2);
}
return result;
}
// Raise the base at the power of exponent
strPow(base, exponent) {
let result;
if (this.multitasking) {
this.addTask('', `LOAD ${base}`);
this.addTask('', `POW ${exponent}`);
result = this.addTask('', `STORE`);
} else {
result = SuperScalar.#corePow(str1, str2);
}
return result;
}
}