View Single Post
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: Where does Modulus fit in with PEMDAS?

 
0
  #3
Nov 9th, 2008
Originally Posted by VernonDozier View Post
When in doubt, write a program! It's faster and more accurate than research.
ummm....

google seems to quickly turn up a bunch of results for this question, e.g. http://www.cppreference.com/wiki/operator_precedence
You're right, division/multiplication/modulus all have equal precedence.

Originally Posted by VernonDozier View Post
... It's one of the reasons I never liked "PEMDAS". If all you remember is the acronym, you always multiply before dividing, which is wrong, and you always add before subtracting, which is also wrong.
I agree, if you multiply before dividing, the answer may be wrong, as in e.g. 2 / 5 * 9
Likewise, if you add before subtracting, e.g. 2 - 5 + 9

However, reversing the above should result in correct answers always: PEDMSA (doesn't really roll off the tongue anymore though)

I'm pretty sure you'll have to use the left-to-right rule for operators where there is >2 operators having equal precedence (i.e. when you add modulus to the mix).
Reply With Quote