Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modulo in order of operation

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

like image 805
Adam Harte Avatar asked Jun 24 '10 21:06

Adam Harte


People also ask

What is the precedence of modulo?

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.

Does Modulo have higher precedence?

The multiplication, modulus and division are evaluated first in left-to-right order (i.e., they associate from left to right) because they have higher precedence than addition and subtraction. The addition and subtraction are applied next.

What is mod in order?

The multiplicative order of a number a modulo n is the order of a in the multiplicative group whose elements are the residues modulo n of the numbers coprime to n, and whose group operation is multiplication modulo n.

What is the correct order of operations?

The order of operations is a rule that tells the correct sequence of steps for evaluating a math expression. We can remember the order using PEMDAS: Parentheses, Exponents, Multiplication and Division (from left to right), Addition and Subtraction (from left to right).


1 Answers

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.

like image 168
walkytalky Avatar answered Oct 03 '22 10:10

walkytalky