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 = [];
|
const stack = [];
|
||||||
for (const token of queue) {
|
for (const token of queue) {
|
||||||
if (typeof token === "bigint") {
|
if (typeof token === "bigint") {
|
||||||
stack.push(token % modulus);
|
stack.push(token);
|
||||||
} else if (token === "+") {
|
} else if (token === "+") {
|
||||||
const [a, b] = binaryOpPop(stack);
|
let [a, b] = binaryOpPop(stack);
|
||||||
|
a %= modulus;
|
||||||
|
b %= modulus;
|
||||||
const c = (a + b) % modulus;
|
const c = (a + b) % modulus;
|
||||||
stack.push(c);
|
stack.push(c);
|
||||||
} else if (token === "-") {
|
} else if (token === "-") {
|
||||||
const [a, b] = binaryOpPop(stack);
|
let [a, b] = binaryOpPop(stack);
|
||||||
|
a %= modulus;
|
||||||
|
b %= modulus;
|
||||||
const c = (a - b) % modulus;
|
const c = (a - b) % modulus;
|
||||||
stack.push(c);
|
stack.push(c);
|
||||||
} else if (token === "*") {
|
} else if (token === "*") {
|
||||||
const [a, b] = binaryOpPop(stack);
|
let [a, b] = binaryOpPop(stack);
|
||||||
|
a %= modulus;
|
||||||
|
b %= modulus;
|
||||||
const c = (a * b) % modulus;
|
const c = (a * b) % modulus;
|
||||||
stack.push(c);
|
stack.push(c);
|
||||||
} else if (token === "/") {
|
} else if (token === "/") {
|
||||||
const [a, b] = binaryOpPop(stack);
|
let [a, b] = binaryOpPop(stack);
|
||||||
|
a %= modulus;
|
||||||
|
b %= modulus;
|
||||||
const binv = modinv(b, modulus);
|
const binv = modinv(b, modulus);
|
||||||
const c = (a * binv) % modulus;
|
const c = (a * binv) % modulus;
|
||||||
stack.push(c);
|
stack.push(c);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue