![]() | Chapter 14: Units | ![]() ![]() |
14.2. Numbers |
What Inform calls a "number" is a whole number in the range
-32768, -32767, ..., -3, -2, -1, 0, 1, 2, 3, ..., 32767
We are allowed to perform the same operations on numbers as are provided by a typical four-function calculator: addition, subtraction, multiplication and division. We are allowed to write these either in words or in symbols:
the score + 10
100 - the score
10 * 21
144 / 12
the score plus 10
100 minus the score
10 times 21
10 multiplied by 21
144 divided by 12
If we use the symbols, then spaces around them are obligatory: really, they are words which just happen to be spelt with symbols instead of letters.
With addition and subtraction, what we often want is to add or subtract some amount from a named variable, and a convenient abbreviation is provided for this:
increase the target by 10;
decrease the target by 5;
Division rounds down to the nearest integer (and we must never divide by 0, of course). If we try dividing 26 by 3, we will get the answer 8: but 3 does not go into 26 exactly. We can obtain the remainder, if we want to, like so:
remainder after dividing 26 by 3
the value of which is 2, because 3 goes into 26 eight times, with remainder 2.
We can compare numbers using either the traditional computer-programming symbols, or using words:
if the score is less than 10
if the score < 10
and similarly for "greater than", "at least" and "at most", with the symbols ">", ">=" and "<=". But we are not allowed the equals sign: for that we need only use "is" -
if the score is 10
Finally, as we have seen, numbers up to twelve may be written out, but larger ones must be written as numerals. So "twelve" or "12", but "13" only.
| ![]() Smoke which spreads through the rooms of the map, but only every other turn. |
|
Previous | Contents | Next |