math-expression-evaluator icon indicating copy to clipboard operation
math-expression-evaluator copied to clipboard

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

Open dmathisen opened this issue 2 years ago • 3 comments

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

dmathisen avatar Aug 02 '22 21:08 dmathisen

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..

bugwheels94 avatar Aug 04 '22 12:08 bugwheels94

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.

dmathisen avatar Aug 04 '22 12:08 dmathisen

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

marcusig avatar Apr 20 '23 08:04 marcusig