math-parser icon indicating copy to clipboard operation
math-parser copied to clipboard

Questions about functions using commas and ** operator

Open New0 opened this issue 6 years ago • 3 comments

Hello and thank you for publishing the package.

I've been trying pow() and log() with two parameters but the , returned the Unknown token exception.

The ** operator returned a Syntax error exception.

Code example

$parser = new StdMathParser();
$AST = $parser->parse( 'pow(33,10)' );
$evaluator = new Evaluator();
//$total returns the exceptions explained above
$total = $AST->accept($evaluator);
$parser = new StdMathParser();
$AST = $parser->parse( '3**10' );
$evaluator = new Evaluator();
//$total returns the exceptions explained above
$total = $AST->accept($evaluator);

Did I forget a step for those scenarios ? All the other math functions and operator work as expected in my case. Thanks again

New0 avatar May 06 '19 11:05 New0

Hello, I see that pow() and ** are not supported and that log() only accepts one argument.

Is that correct ?

New0 avatar May 07 '19 09:05 New0

The standard lexer/parser that ships with the project only uses ^ for exponentiation, and log for the logarithm to base e. If you want to change that, I would suggest that you implement your own lever. Use StdMathLexer as inspiration.

Actually, let me think a little more about this. I just realised that there is no obvious way to add functions taking several comma-separated arguments.

mossadal avatar May 17 '19 22:05 mossadal

Hello @mossadal , thank you for your answer.

Yes I was wrong considering that php functions would also be valid/accepted formulas, but I realize it doesn't have to be the case.

I also tried to add comas as a valid token but realized I couldn't develop the logic to for coma separated arguments at the moment.

Thank you again.

New0 avatar May 19 '19 09:05 New0