Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown constant i #14

Closed
maximl337 opened this issue Aug 20, 2018 · 3 comments
Closed

Unknown constant i #14

maximl337 opened this issue Aug 20, 2018 · 3 comments

Comments

@maximl337
Copy link

maximl337 commented Aug 20, 2018

        $expression = 'a + i';
        $variableValues = ['a' => 1, 'i' => 1];
        // Generate an abstract syntax tree
        $AST = $this->parser->parse($expression);

        // Set variables with value ['x' => 1, ..]
        $this->evaluator->setVariables($variableValues);

        // pass evaluator to Abstract Syntax Tree
        $value = $AST->accept($this->evaluator);
        
        return $value;

Any expression that contains i seems the throw the following expception:

MathParser\Exceptions\UnknownConstantException: Unknown constant i.

Replacing i with any other alphabet seems to fix the issue.

@mossadal
Copy link
Owner

i is reserved as the imaginary unit. If you want to use i as a regular variable, you can replace StdMathLexer with a version that doesn't recognize i. (Remove line 129.)

@mossadal mossadal reopened this Sep 14, 2018
@mossadal
Copy link
Owner

Actually, I had a closer look, and i shouldn't be reserved in StdMathLexer, just in ComplexLexer. An update is on its way.

@mossadal
Copy link
Owner

This is now fixed in 1.3.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants