Use that in a program, and it will cause the bit pattern for the number 13 to come into existence inside the computer’s memory.
Computer memory used to be much smaller, and people tended to use groups of 8 or 16 bits to represent their numbers. It was easy to accidentally overflow such small numbers—to end up with a number that did not fit into the given number of bits. Today, even computers that fit in your pocket have plenty of memory, so you are free to use 64-bit chunks, and you need to worry about overflow only when dealing with truly astronomical numbers.
For very big or very small numbers, you may also use scientific notation by adding an e (for exponent), followed by the exponent of the number.
That is 2.998 x 108 = 299,800,000.
Calculations with whole numbers (also called integers) smaller than the aforementioned 9 quadrillion are guaranteed to always be precise. Unfortunately, calculations with fractional numbers are generally not. Just as n (pi) cannot be precisely expressed by a finite number of decimal digits, many numbers lose some precision when only 64 bits are available to store them. This is a shame, but it causes practical problems only in specific situations. The important thing is to be aware of it and treat fractional digital numbers as approximations, not as precise values.
100 + 4 * 11
The + and * symbols are called operators. The first stands for addition, and the second stands for multiplication. Putting an operator between two values will apply it to those values and produce a new value.
But does the example mean “add 4 and 100, and multiply the result by 11,” or is the multiplication done before the adding? As you might have guessed, the multiplication happens first. But as in mathematics, you can change this by wrapping the addition in parentheses.
(100 + 4) * 11
For subtraction, there is the – operator, and division can be done with the / operator.
When operators appear together without parentheses, the order in which they are applied is determined by the precedence of the operators. The example shows that multiplication comes before addition. The / operator has the same precedence as *. Likewise for + and -. When multiple operators with the same precedence appear next to each other, as in 1-2 + 1, they are applied left to right: (1 – 2) + 1.
These rules of precedence are not something you should worry about. When in doubt, just add parentheses.
There is one more arithmetic operator, which you might not immediately recognize. The % symbol is used to represent the remainder operation. X % Y is the remainder of dividing X by Y. For example, 314 % 100 produces 14, and 144 % 12 gives 0. The remainder operator’s precedence is the same as that of multiplication and division. You’ll also often see this operator referred to as modulo.
The first two are Infinity and -Infinity, which represent the positive and negative infinities. Infinity – 1 is still Infinity, and so on. Don’t put too much trust in infinity-based computation, though. It isn’t mathematically sound, and it will quickly lead to the next special number: NaN.
NaN stands for “not a number,” even though it is a value of the number type. You’ll get this result when you, for example, try to calculate 0/0 (zero divided by zero), Infinity – Infinity, or any number of other numeric operations that don’t yield a meaningful result.
No Starch Press; 3rd edition.