expr-eval icon indicating copy to clipboard operation
expr-eval copied to clipboard

Exponential operator

Open iserranoe opened this issue 4 years ago • 1 comments

The exponential operator used with Parser is ^; however, javascript exponential operator is **. Is there a way for Parser to accept ** as exponential operator?

//Standard JavaScript exponential
> 2**3
8
//eval function exponential
> eval('2**3')
8
//Not working with Parser
> Parser = require('expr-eval').Parser
[Function: Parser] { parse: [Function], evaluate: [Function] }
> Parser.evaluate('2**3')
Thrown:
Error: unexpected TOP: *
     .....
//Working with other operator
> Parser.evaluate('2^3')
8

iserranoe avatar Jul 07 '20 09:07 iserranoe

That's a good idea. I'm not a big fan of having multiple syntaxes for the same thing, but especially with JavaScript using **, that would align with people's expectations. We could make it an option, but the extra complexity doesn't seem worth it, and it's easy enough to support both. There also shouldn't be any backward-compatibility issues, since ** is current a syntax error.

silentmatt avatar Jul 07 '20 17:07 silentmatt