< previous page page_530 next page >

Page 530
Also because of representational errors, we should never compare floating point numbers for exact equality. Rarely are two floating point numbers exactly equal, and thus they should be compared only for near equality. If the difference between the two numbers is less than some acceptable small value, we can consider them equal for the purposes of the given problem.
Implementation of Floating Point Numbers in the Computer
Let's formally define some of the terms we used informally in the previous section.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Significant Digits Those digits from the first nonzero digit on the left to the last nonzero digit on the right (plus any zero digits that are exact).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Precision The maximum number of significant digits.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Representational Error Arithmetic error that occurs when the precision of the true result of an arithmetic operation is greater than the precision of the machine.
All computers limit the precision of a floating point number, although most machines use binary rather than decimal arithmetic. In our representation, we used only 5 digits to simplify the examples, and some computers really are limited to only 4 or 5 digits of precision. A more typical system might provide 6 significant digits for float values, 15 digits for double values, and 19 for the long double type. We have shown only a single-digit exponent, but most systems allow 2 digits for the float type and up to 4-digit exponents for type long double.
When you declare a floating point variable, part of the memory location is assumed to contain the exponent, and the number itself (called the mantissa) is assumed to be in the balance of the location. The system is called floating point representation because the number of significant digits is fixed, and the decimal point conceptually floats (is moved to different positions as necessary). In our coding scheme, every number is stored as four digits, with the leftmost being nonzero, and the exponent adjusted accordingly. The number 1,000,000 was stored as
0530-01.gif
and 0.1032 was stored as
0530-02.gif

 
< previous page page_530 next page >