jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
514 stars 82 forks source link

solveFor(...) call hangs if a constant with many decimal digits are present #589

Closed cihancimen closed 3 years ago

cihancimen commented 3 years ago

Following code hangs.

const equation = "bop_auc___plan=eop_cost___plan / 3416.3333333333344"
const variableToSolve = "eop_cost___plan"
const factoredEquation = nerdamer(equation).solveFor(variableToSolve).toString()
// Hangs in solveFor call

Reducing number of digits in the constant allows nerdamer to solve the equation

const equation = "bop_auc___plan=eop_cost___plan / 3416.3333"
const variableToSolve = "eop_cost___plan"
const factoredEquation = nerdamer(equation).solveFor(variableToSolve).toString()
// "(34163333/10000)*bop_auc___plan"

@jiggzson Here is the stack trace where the hanging seemingly occurs.

primeFactors (nerdamer.core.js:2402)
testPow (nerdamer.core.js:8458)
Parser.pow (nerdamer.core.js:9609)
getNth (nerdamer.core.js:3303)
isToNth (nerdamer.core.js:3322)
isCube (nerdamer.core.js:3358)
cubeFactor (Algebra.js:2241)
_factor (Algebra.js:2425)
factor (Algebra.js:2142)
solve (Solve.js:1296)
core.Expression.solveFor (Solve.js:220)
(anonymous) (VM629:3)
jiggzson commented 3 years ago

@cihancimen, I'll check it out. Thanks.