From e895c2296cfccf4df4184548aa1594e5507922b1 Mon Sep 17 00:00:00 2001 From: bangonicdd <157843588+bangonicdd2@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:26:50 +0900 Subject: [PATCH 1/2] fix: treating unary minus in calcString --- src/ts/process/infunctions.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ts/process/infunctions.ts b/src/ts/process/infunctions.ts index e0ab4f40..70f39659 100644 --- a/src/ts/process/infunctions.ts +++ b/src/ts/process/infunctions.ts @@ -27,7 +27,11 @@ function toRPN(expression:string) { let lastToken = '' for(let i = 0; i < expression.length; i++) { - if(operatorsKeys.includes(expression[i])) { + const char = expression[i] + if (char === '-' && (i === 0 || operatorsKeys.includes(expression[i - 1]) || expression[i - 1] === '(')) { + lastToken += char + } + else if (operatorsKeys.includes(char)) { if(lastToken !== '') { expression2.push(lastToken) } @@ -35,10 +39,10 @@ function toRPN(expression:string) { expression2.push('0') } lastToken = '' - expression2.push(expression[i]) + expression2.push(char) } else{ - lastToken += expression[i] + lastToken += char } } From 681846cc931fbb02ab0d8bbc635e35fe2557a5a1 Mon Sep 17 00:00:00 2001 From: bangonicdd <157843588+bangonicdd2@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:23:52 +0900 Subject: [PATCH 2/2] fix: Add missing '!=' implementation in calcString --- src/ts/process/infunctions.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ts/process/infunctions.ts b/src/ts/process/infunctions.ts index 70f39659..8c2b508a 100644 --- a/src/ts/process/infunctions.ts +++ b/src/ts/process/infunctions.ts @@ -17,6 +17,7 @@ function toRPN(expression:string) { '≤': {precedence: 1, associativity: 'Left'}, '≥': {precedence: 1, associativity: 'Left'}, '=': {precedence: 1, associativity: 'Left'}, + '≠': {precedence: 1, associativity: 'Left'}, '!': {precedence: 5, associativity: 'Right'}, }; const operatorsKeys = Object.keys(operators); @@ -98,6 +99,7 @@ function calculateRPN(expression:string) { case '≤': stack.push(a <= b ? 1 : 0); break; case '≥': stack.push(a >= b ? 1 : 0); break; case '=': stack.push(a === b ? 1 : 0); break; + case '≠': stack.push(a !== b ? 1 : 0); break; case '!': stack.push(b ? 0 : 1); break; } } @@ -125,7 +127,14 @@ function executeRPNCalculation(text:string) { return "0" } return parsed.toString() - }).replace(/&&/g, '&').replace(/\|\|/g, '|').replace(/<=/g, '≤').replace(/>=/g, '≥').replace(/==/g, '=').replace(/null/gi, '0') + }) + .replace(/&&/g, '&') + .replace(/\|\|/g, '|') + .replace(/<=/g, '≤') + .replace(/>=/g, '≥') + .replace(/==/g, '=') + .replace(/!=/g, '≠') + .replace(/null/gi, '0') const expression = toRPN(text); const evaluated = calculateRPN(expression); return evaluated