View Single Post
Join Date: Jan 2008
Posts: 3,752
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 491
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Where does Modulus fit in with PEMDAS?

 
0
  #6
Nov 9th, 2008
Originally Posted by Alex Edwards View Post
Now I'm curious...

When would it ever matter if you multiplied before dividing or subtract before adding?

Multiplication and division are technically the same.

Your expression 2 / 5 * 9 is the same as 2 * .2 * 9 so why in the world would it matter if you multiplied first instead of dividing?

Maybe it's because you're using int division?

The same argument exists for subtracting and adding. 2 - 5 + 9 is the same as 2 + -5 + 9 which will yield the same results despite whether you add or subtract first.

Are you using unsigned types?


And if modulus has equal precedence then I suppose my program is technically correct, but I would like it to have either stronger or weaker precedence before MD or after MD.

And Vernon I know you are the mathy-type so I am looking over your post carefully, trying to understand what you mean when you say I need a third option (i.e. Modulus before Division but after Multiplication), when M and D are technically the same?

-Alex
Consider 2 - 5 + 9 and 9 / 3 * 3

(2 - 5) + 9 is different from 2 - (5 + 9)
(9 / 3) * 3 is different from 9 / (3 * 3)

If + and - have equal precedence, and so do * and /, then the left implementations are the correct implementations. If * outranks / and + outranks -, then the implementations on the right are the correct implementations.

Since they DO have equal precedence, 2 - 5 + 9 = (2 - 5) + 9 and
9 / 3 * 3 = (9 / 3) * 3.

It has nothing to do with the fact that they are integers. The option you need in your poll that you don't have is "Multiply, divide, and mod all have the same precedence", which is the correct answer. Thus, what operation occurs first depends on their order from left to right in the term, as the example below:

9 / 3 * 3 = (9 / 3) * 3

Division comes first since the / is to the left of the *.
Reply With Quote