bugwheels94 / math-expression-evaluator

Math JS library. Super advanced & efficient Math expression evaluator
MIT License
197 stars 33 forks source link

[Feature request] Support for conditional operator a ? b : c #50

Open dmathisen opened 2 years ago

dmathisen commented 2 years ago

It would be great to support conditional expressions (like "if statements").

Similar to math.js "Conditional expression" seen here https://mathjs.org/docs/expressions/syntax.html

image

bugwheels94 commented 2 years ago

mathjs has their own parser, AST etc and all while this library is just a modified version of dijkstra's algorithm. > < == etc symbols i can implement but boolean ? number : number. it means if boolean ? X should give X or boolean and X:Y should give Y if X = boolean or X if X != boolean. I will think and try my best about it in coming weekend or so..

dmathisen commented 2 years ago

No problem - it sounds like a pretty complicated feature (do you allow nested "if" conditionals?). 1 > 2 ? 3 : 2 < 4 ? 5 : 6 => 3 1 < 2 ? 3 : 2 < 4 ? 5 : 6 => 5

It looks like it can get complicated and it's not a rush for me (I figured out a workaround for now). Thank you for responding, regardless.

marcusig commented 1 year ago

Hi there, I would like to vote for this feature, if is possible! Thanks for the great work with this :)