Operator Precedence
The calculator performs operations in the following order (highest to lowest):
- Parentheses: ( ) calculated first
- Functions: sin, cos, tan, sqrt, log, etc.
- Factorial: !
- Exponentiation: ^ (right associative)
- Unary operators: +x, -x
- Multiplication/Division: *, /
- Addition/Subtraction: +, -
Using Parentheses
Parentheses change the default order of operations. Expressions inside parentheses are calculated first.
- Supports multiple levels of nested parentheses
- Innermost parentheses are calculated first
- Within the same level, operations follow precedence order
Examples
Example 1: Basic precedence
Input:
2 + 3 * 4
Result:
14
Multiplication first: 3*4=12, then add: 2+12=14
Example 2: Using parentheses to change order
Input:
(2 + 3) * 4
Result:
20
Parentheses first: 2+3=5, then multiply: 5*4=20
Example 3: Nested parentheses
Input:
((2 + 3) * (4 - 1))
Result:
15
First 2+3=5 and 4-1=3, then 5*3=15
Example 4: Exponentiation precedence
Input:
2^3^2
Result:
512
Exponentiation is right-associative: 2^(3^2) = 2^9 = 512
Example 5: Factorial precedence
Input:
3! + 2
Result:
8
Factorial first: 3!=6, then add: 6+2=8
Example 6: Complex expression
Input:
sin(30) + sqrt(16) * 2
Result:
8.5
sin(30)=0.5, sqrt(16)=4, 0.5+4*2=0.5+8=8.5