views:

71

answers:

6

Where does modulo come in the mathematical order of operation? I am guessing it is similar to division, but before or after?

+3  A: 

At least in C++ and Java, modulo (%) has the same level of precedence as multiplication and division.

Since %, / and * are (usually) left-associative, they are evaluated left to right.

(Thanks to Mark for pointing out operator associativity)

Jen
`In the absence of parentheses, operators of the same level of precedence are simply evaluated left to right.` Not always. See Operator Associativity: http://en.wikipedia.org/wiki/Operator_associativity
Mark Byers
A: 

The modulo operator %, as used in many computer programming languages, is not common in pure mathematics. So it is rather a question of how the operator is treated in programming languages, and this differ between different langauges.

Andreas Rejbrand
+5  A: 

If your question is about programming languages then yes, % has the same order as * and /

See this table.

Soufiane Hassou
Nice to know most languages tend to follow the same standard.
Mau
+1 for the link.
Robert Hui
A: 

For C++ it has the same precedence as multiplication and division. Take them as they come, left to right.

John at CashCommons
+2  A: 

This depends on the language, but in C style languages % is the same precedence as * and /. This means that if it appears in the same expression (without parentheses) the order depends on the associativity. In this case % is usually left-associative, so the operators will be executed in left-to-right order.

walkytalky
+2  A: 

The relative precedence levels of operators found in many C-style languages are as follows:

alt text

Mehper C. Palavuzlar
Great to have this inline in the question. But what's your source?
dreeves
Source: http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages
Mehper C. Palavuzlar