Operator Precedence

The calculator performs operations in the following order (highest to lowest):

  1. Parentheses: ( ) calculated first
  2. Functions: sin, cos, tan, sqrt, log, etc.
  3. Factorial: !
  4. Exponentiation: ^ (right associative)
  5. Unary operators: +x, -x
  6. Multiplication/Division: *, /
  7. 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

Important Notes

  1. Ensure parentheses are properly paired; missing closing parentheses will cause errors
  2. Exponentiation is right-associative: a^b^c = a^(b^c)
  3. Same precedence operators are evaluated left to right (except exponentiation)
  4. For complex expressions, use extra parentheses to make intent clearer