jiggzson / nerdamer

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

cant build function #545

Closed MAGNETO903 closed 4 years ago

MAGNETO903 commented 4 years ago

I tried var f = nerdamer('acos((-x)^(1/6))').buildFunction();

but i get error: TypeError: Cannot read property 'toString' of undefined

but if i try var f = nerdamer('acos((x)^(1/6))').buildFunction(); it's works

when in expression i have -x, nerdamer breaks

but if i set function root nerdamer.setFunction('root', ['n', 'x'], 'x^(1/n)');

and try to build function: nerdamer('acos(root(6, -x))').buildFunction();

it's works too what's wrong?

jiggzson commented 4 years ago

@MAGNETO903, buildFunction is getting confused by the parentheses. The quickest fix is to add

if(symbol.fname === '') {
    symbol = Symbol.unwrapPARENS(symbol);
}

at the top of the ftext function here. I'll add it.

MAGNETO903 commented 4 years ago

You mean at 11152 line? var ftext = function (symbol, xports) { xports = xports || []; ...