Basic Arithmetic Operations
Learn how to evaluate basic arithmetic expressions with addition, subtraction, multiplication, and division. Understand operator precedence and parentheses grouping.
Detailed Explanation
Basic Arithmetic in Math Expressions
The four fundamental arithmetic operations form the foundation of every mathematical expression:
- Addition (+): Combines two values.
5 + 3equals8. - Subtraction (-): Finds the difference.
10 - 4equals6. - Multiplication (*): Scales a value.
6 * 7equals42. - Division (/): Splits a value.
20 / 4equals5.
Operator Precedence (PEMDAS/BODMAS)
When an expression contains multiple operators, the parser follows standard mathematical precedence:
- Parentheses
( )are evaluated first. - Exponentiation
^comes next. - Multiplication, Division, Modulo
* / %are evaluated left to right. - Addition, Subtraction
+ -are evaluated last, left to right.
Example
2 + 3 * 4 = 14 (not 20, because * binds tighter than +)
(2 + 3) * 4 = 20 (parentheses override precedence)
10 - 2 * 3 + 1 = 5 (2*3=6, then 10-6+1=5)
Modulo Operator
The % operator returns the remainder after integer division:
17 % 5 = 2 (17 divided by 5 is 3 remainder 2)
10 % 3 = 1
100 % 7 = 2
This is useful for determining whether a number is even (n % 2 == 0)
or for cyclic indexing in programming.
Division by Zero
Dividing by zero is undefined in mathematics. The evaluator catches this and returns a clear error message rather than producing Infinity or NaN.
Use Case
A student verifying homework answers by checking multi-step arithmetic expressions against the evaluator, or a developer quickly computing values during debugging.