Modulo in order of operation

MathExpression

Math Problem Overview


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

Math Solutions


Solution 1 - Math

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.

Solution 2 - Math

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

table

Wikipedia - Order of Operations

Solution 3 - Math

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 http://en.wikipedia.org/wiki/Operator_associativity">operator associativity)

Solution 4 - Math

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

See this table.

Solution 5 - Math

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.

Solution 6 - Math

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdam HarteView Question on Stackoverflow
Solution 1 - MathwalkytalkyView Answer on Stackoverflow
Solution 2 - MathMehper C. PalavuzlarView Answer on Stackoverflow
Solution 3 - MathTony the PonyView Answer on Stackoverflow
Solution 4 - MathSoufiane HassouView Answer on Stackoverflow
Solution 5 - MathAndreas RejbrandView Answer on Stackoverflow
Solution 6 - MathJohnView Answer on Stackoverflow