diff --git a/src/artigen/math/mathSolver.ts b/src/artigen/math/mathSolver.ts index 071ad6f..ec6009a 100644 --- a/src/artigen/math/mathSolver.ts +++ b/src/artigen/math/mathSolver.ts @@ -17,7 +17,7 @@ import { getMatchingParenIdx } from 'artigen/utils/parenBalance.ts'; // mathSolver is a function that recursively solves the full roll and math export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => { // Initialize PEMDAS - const signs = ['^', '*', '/', '%', '+', '-']; + const signs = ['^', '**', '*', '/', '%', '+', '-']; const stepSolve: SolvedStep = { total: 0, details: '', @@ -88,7 +88,11 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => // At this point, conf should be [num, op, num, op, num, op, num, etc] // Evaluate all EMDAS by looping thru each tier of operators (exponential is the highest tier, addition/subtraction the lowest) - const allCurOps = [['^'], ['*', '/', '%'], ['+', '-']]; + const allCurOps = [ + ['^', '**'], + ['*', '/', '%'], + ['+', '-'], + ]; allCurOps.forEach((curOps) => { loggingEnabled && log(LT.LOG, `Evaluating roll ${JSON.stringify(conf)} | Evaluating ${JSON.stringify(curOps)}`); // Iterate thru all operators/operands in the conf @@ -150,6 +154,7 @@ export const mathSolver = (conf: MathConf[], wrapDetails = false): SolvedStep => // Finally do the operator on the operands, throw an error if the operator is not found switch (conf[i]) { case '^': + case '**': subStepSolve.total = Math.pow(oper1, oper2); break; case '*': diff --git a/src/artigen/math/mathTokenizer.ts b/src/artigen/math/mathTokenizer.ts index b56b3f7..46d1542 100644 --- a/src/artigen/math/mathTokenizer.ts +++ b/src/artigen/math/mathTokenizer.ts @@ -17,7 +17,7 @@ import { loggingEnabled } from 'artigen/utils/logFlag.ts'; import { assertParenBalance } from 'artigen/utils/parenBalance.ts'; // minusOps are operators that will cause a negative sign to collapse into a number (in cases like + - 1) -const minusOps = ['(', '^', '*', '/', '%', '+', '-']; +const minusOps = ['(', '^', '**', '*', '/', '%', '+', '-']; const allOps = [...minusOps, ')']; export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResults: number[]): [ReturnData[], CountDetails[], RollDistributionMap[]] => { @@ -31,7 +31,7 @@ export const tokenizeMath = (cmd: string, modifiers: RollModifiers, previousResu .replace(cmdSplitRegex, '') .replace(internalWrapRegex, '') .replace(/ /g, '') - .split(/([-+()*/^]|(? x); loggingEnabled && log(LT.LOG, `Split roll into mathConf ${JSON.stringify(mathConf)}`);