*** Welcome to piglix ***

Order of operations


In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.

For example, in mathematics and most computer languages, multiplication is granted a higher precedence than addition. Thus, the expression 2 + 3 × 4 is interpreted to have the value 14, not 20. These conventions exist to eliminate ambiguity while allowing notation to be as brief as possible. Where it is desired to override the precedence conventions, or even simply to emphasize them, parentheses ( ) (sometimes replaced by brackets [ ] or braces { } for readability) can indicate an alternate order or reinforce the default order to avoid confusion. Thus the preceding expression could be changed to (2 + 3) × 4 to produce 20, or 2 + (3 × 4) to produce 14 (the default interpretation if there are no parentheses).

Since the introduction of modern algebraic notation, multiplication has taken precedence over addition. Thus 3 + 4 × 5 = 4 × 5 + 3 = 23.

When exponents were first introduced in the 16th and 17th centuries, exponents took precedence over both addition and multiplication and could be placed only as a superscript to the right of their base. Thus 3 + 52 = 28 and 3 × 52 = 75. To change the order of operations, originally a vinculum (an overline or underline) was used. Today, parentheses or brackets are used to explicitly denote precedence by grouping parts of an expression that should be evaluated first. Thus resulting in (2 + 3) × 4 = 20 to force addition to precede multiplication or (3 + 5)2 = 64 to force addition to precede exponentiation.

The order of operations used throughout mathematics, science, technology and many computer programming languages is expressed here:

This means that if a mathematical expression is preceded by one binary operator and followed by another, the operator higher on the list should be applied first. The commutative and associative laws of addition and multiplication allow adding terms in any order, and multiplying factors in any order—but mixed operations must obey the standard order of operations.


...
Wikipedia

...