|
|
| |
|
|
|
|
Practical Implications of Limited Precision |
|
|
|
| |
|
|
|
|
A discussion of representational, overflow, underflow, and cancellation errors may seem purely academic. In fact, these errors have serious practical implications in many problems. We close this section with three examples illustrating how limited precision can have disastrous effects. |
|
|
|
| |
|
|
|
|
During the Mercury space program, several of the spacecraft splashed down a considerable distance from their computed landing points. This delayed the recovery of the spacecraft and the astronaut, putting both in some danger. Eventually, the problem was traced to an imprecise representation of the Earth's rotation period in the program that calculated the landing point. |
|
|
|
| |
|
|
|
|
As part of the construction of a hydroelectric dam, a long set of high-tension cables had to be constructed to link the dam to the nearest power distribution point. The cables were to be several miles long, and each one was to be a continuous unit. (Because of the high power output from the dam, shorter cables couldn't be spliced together.) The cables were constructed at great expense and strung between the two points. It turned out that they were too short, however, so another set had to be manufactured. The problem was traced to errors of precision in calculating the length of the catenary curve (the curve that a cable forms when hanging between two points). |
|
|
|
| |
|
|
|
|
An audit of a bank turned up a mysterious account with a large amount of money in it. The account was traced to an unscrupulous programmer who had used limited precision to his advantage. The bank computed interest on its accounts to a precision of a tenth of a cent. The tenths of cents were not added to the customers' accounts, so the programmer had the extra tenths for all the accounts summed and deposited into an account in his name. Because the bank had thousands of accounts, these tiny amounts added up to a large amount of money. Because the rest of the bank's programs did not use as much precision in their calculations, the scheme went undetected for many months. |
|
|
|
| |
|
|
|
|
The moral of this discussion is twofold: 1) The results of floating point calculations are often imprecise, and these errors can have serious consequences; and 2) If you are working with extremely large numbers or extremely small numbers, you need more information than this book provides and should consult a numerical methods text. |
|
|
|
|
|
|
|
|
|
User-Defined Simple Types |
|
|
|
|
|
|
|
|
The concept of a data type is fundamental to all of the widely used programming languages. One of the strengths of the C++ language is that it allows programmers to create new data types, tailored to meet the needs of a partic- |
|
|
|
|
|