February 2012
Intermediate to advanced
1184 pages
37h 17m
English
Arithmetic operators do what you would expect from learning them in school. They perform some sort of mathematical function on numbers; see Table 1-2.
Table 1-2. Mathematical operators
| Example | Name | Result |
|---|---|---|
$a +
$b | Addition | Sum of $a and
$b |
$a *
$b | Multiplication | Product of $a and
$b |
$a %
$b | Modulus | Remainder of $a divided
by $b |
$a **
$b | Exponentiation | $a to the power of $b |
Yes, we left out subtraction and division—we suspect you can figure out how they should work. Try them and see if you’re right. (Or cheat and look in Chapter 3.) Arithmetic operators are evaluated in the order your math teacher taught you (exponentiation before multiplication; multiplication before addition). You can always use parentheses to make it come out differently.
Read now
Unlock full access