don't mod values when pushed
This commit is contained in:
parent
8a75177060
commit
f8324b8a30
18
main.js
18
main.js
|
|
@ -70,21 +70,29 @@ function compute(queue, modulus) {
|
|||
const stack = [];
|
||||
for (const token of queue) {
|
||||
if (typeof token === "bigint") {
|
||||
stack.push(token % modulus);
|
||||
stack.push(token);
|
||||
} else if (token === "+") {
|
||||
const [a, b] = binaryOpPop(stack);
|
||||
let [a, b] = binaryOpPop(stack);
|
||||
a %= modulus;
|
||||
b %= modulus;
|
||||
const c = (a + b) % modulus;
|
||||
stack.push(c);
|
||||
} else if (token === "-") {
|
||||
const [a, b] = binaryOpPop(stack);
|
||||
let [a, b] = binaryOpPop(stack);
|
||||
a %= modulus;
|
||||
b %= modulus;
|
||||
const c = (a - b) % modulus;
|
||||
stack.push(c);
|
||||
} else if (token === "*") {
|
||||
const [a, b] = binaryOpPop(stack);
|
||||
let [a, b] = binaryOpPop(stack);
|
||||
a %= modulus;
|
||||
b %= modulus;
|
||||
const c = (a * b) % modulus;
|
||||
stack.push(c);
|
||||
} else if (token === "/") {
|
||||
const [a, b] = binaryOpPop(stack);
|
||||
let [a, b] = binaryOpPop(stack);
|
||||
a %= modulus;
|
||||
b %= modulus;
|
||||
const binv = modinv(b, modulus);
|
||||
const c = (a * binv) % modulus;
|
||||
stack.push(c);
|
||||
|
|
|
|||
Loading…
Reference in New Issue