Arithmetic in Programming – Maths in Code
Every computer program runs on arithmetic. From the simplest calculator app to artificial intelligence, the four operations are the foundation of all computation.
The modulo operation used constantly in programming has a formal mathematical origin: the German mathematician Carl Friedrich Gauss introduced modular arithmetic – sometimes nicknamed “clock arithmetic” because it behaves like the hours on a clock face wrapping back to 1 after 12 – in his 1801 book Disquisitiones Arithmeticae, one of the most influential number theory texts ever written. When early programming languages such as FORTRAN (1957) and later C (1972) were designed, their creators built the % and integer-division operators directly on Gauss's centuries-old framework, which is why modern code for tasks like checking whether a number is even, wrapping an index around an array, or converting seconds into hours and minutes all quietly rely on 19th-century number theory.
Arithmetic Operators in Code
| Operation | Python / JS | Example | Result |
|---|---|---|---|
| Addition | + | 5 + 3 | 8 |
| Subtraction | − | 10 − 4 | 6 |
| Multiplication | * | 6 * 7 | 42 |
| Division | / | 15 / 4 | 3.75 |
| Integer division | // | 15 // 4 | 3 |
| Modulo (remainder) | % | 15 % 4 | 3 |
| Exponentiation | ** | 2 ** 8 | 256 |
Order of Operations in Code
Programming languages follow the same precedence rules as BODMAS. Parentheses override everything.
Integer vs Float Division
The Modulo Operator
% returns the remainder. It is used for checking divisibility, cycling through lists, and time calculations.
Key Takeaways
- All programming arithmetic uses the same rules as written maths.
- / gives a decimal; // gives the whole number quotient.
- % (modulo) gives the remainder.
- Use parentheses to control the order of operations.
