You should absolutely use the eTeX
\numexpr option; it's clear and is supported pretty much everywhere.
If you're interested in the original Knuthian TeX, though, there are also arithmetical operators. For the four functions, you use the TeX primitives
\divide, in a pretty unique and, I think, clever way:
$\x \div \y =$
So first we print the problem we're doing, for demonstrative purposes:
$\x \div \y =$
The next thing we have to do is convert
\y (which TeX views as merely the characters
0, not as the decimal numbers 30 and 10) into count values, which TeX does view as decimal numbers. So we create two counters,
\b, and then assign the decimal number version of our command sequences
\y to them with the following code:
\b have the correct values (30 and 10), we can do our actual arithmetical operation:
This does just what it looks like: it divides
\b, the quotient being stored in
\a. Then we use the
\the directive (another TeX primitive) to assign to
\x, your control sequence from earlier, the new value of
\a. Then, finally, we print our quotient:
That prints the following:
TeX offers three primitives for the four arithmetical operations:
\advance\a by\b Does addition.
\advance\a by-\b Does subtraction.
\multiply\a by\b Does multiplication.
\divide\a by \b Does division.
These all work with counters, glue, muglue, and dimensions, and you can even mix them, though you have to be careful when adding, say, a counter to some glue because the stretchability can be lost.
It is important to note that these all deal with integer division; you won't get fractional values. On the other hand, at least with
dimens, they work in scaled points, which are quite small, so the granularity is pretty impressive.