I am writing a toy mathematical expression parser/calculator, and I have to decide how to handle operator precedence. I realize there is no such thing as a universally agreed upon order of operations that covers everything, but I ask for input anyway, since some ordering/groupings will undoubtedly be less perplexing than others.
In no particular order, the operations I must group/sort are:
- parenthesis
- exponentiation
- functions (i.e. sqrt)
- double factorial and factorial
- unary plus and minus
- implied multiplication
- binary multiply, divide, and modulo
- binary plus and minus
- maybe comma for creating tuples and multivariable functions (e.g. atan2)
Edit: I actually was planning on just copying whatever Wolfram Alpha does, but it turns out it doesn't use a fixed order. Instead it tries to interpret your intent and that causes it to be inconsistent at times.