User | Post |
Squash Monster
Posts: 665/677 |
The cplusplus.com tutorial has some coverage of order of operations.
All that I can give you that's not horribly well-known is that and takes precedence over or.
If it helps to remember: In boolean algebra, and is represented like multiplication. Or is represented like addition. Those two operators work exactly the same as their boolean counterparts when you're using ones and zeroes for true and false, so it's easy to remember. Yes, 1 + 1 = 1. Deal with it. |
HyperLamer
Posts: 7594/8210 |
Well, C technically, but I'm writing code to parse equations so it really doesn't make much difference. And I can't be sure people will use brackets. |
aioria1981
Posts: 163/234 |
In which language are you working? |
beneficii
Posts: 546/567 |
HH,
Just do it like I do: use parantheses.
Ha ha! |
rg_
Posts: 22/26 |
It's called operator precedence and it's language-dependent. Google it for your favourite languages. |
neotransotaku
Posts: 3951/4016 |
logical comes after arithmetic, and logical is evaluated left to right--this is how lazy evaluation works...
so, for your statement the order is
((2 + 2) XOR 7) AND 3 |
HyperLamer
Posts: 7556/8210 |
Makes sense, but what about when there are multiple expressions, like 2 + 2 XOR 7 AND 3? |
mcw
Posts: 136/164 |
i remember seeing a chart showing the exact order of.. everything. it was nice, i wish i remembered the url. but to be safe, just use parenthesis. but knuck is right, it's after all the math operations get figured out. |
knuck
Posts: 1683/1818 |
I think those operators are the last thing to be calculated. Like, if the equation is X²-2/3 AND Y, it'd go (X²-2/3) AND Y
I can be wrong though. |
HyperLamer
Posts: 7553/8210 |
I know the basic order of operations when doing math, but that only covers the basic stuff (brackets, exponents, division, multiplication, addition and subtraction). Where do other operations like XOR and AND fit into this? |