Approximation of Real Numbers

Section: Information
...Subsection: Binary and Other Kinds of Information
... ...Subsubsection: Approximation of Real Numbers

Real numbers cause us a few more problems. These are the numbers that can be represented by fractions or decimal values. (1/3, 2.357, and so on..) The binary notation system does not seem to have room for the decimal point. Computer scientists have worked around this problem too. When a computer is dealing with a real number, it works in something like scientific notation. The number 731.456 is stored in two pieces. The computer stores the value 731456 in binary notation, and in a separate place stores a 3 (again in binary notation), meaning that the decimal place belongs three places from the left. As a user, you don't generally have to know how this works, but you do need to know that computers interpret real numbers differently than integers. (Although at the deepest level they are both stored as a series of 1 and 0 impulses.)

Real Numbers and Error. There are certain kinds of real numbers that are very difficult for the computer to store properly. These are the numbers with endless decimal values. One classic example is the repeating decimal, like you get when you divide 1 by 3. 1/3 = 0.33333.... It goes on forever. Irrational numbers like pi have a similar characteristic. They have an infinite number of digits to the right of the decimal point. Computers have a finite (although often huge) capacity for information. You could fill all the memory of the largest computer in the world with the digits of pi, and still not have a complete solution to pi. (There are a number of interesting research projects out there doing exactly that kind of work.) You could completely fill your computer's capacity with this kind of number, but you probably don't need that close an approximation. 0.3333333 is probably close enough to 1/3 for most calculations, and 3.14159265 is probably close enough to pi for most calculations. Pi is an infinitely precise value, but digital computers do not have infinite precision. The phenomenon is referred to as round - off error, and is important to keep in mind when you are doing very precise calculations. Most of the time it is not a problem, because humans rarely need to be that exact, and there are other complex schemes for dealing with numbers that do not cause this error. You should, however, be aware that round-off error exists.