|
Practical C++ Programming Authors: Oualline S. Published year: 2003 Pages: 206-208/364 |
| I l @ ve RuBoard |
19.1 Floating-Point FormatFloating-point numbers consist of three parts : a sign, a fraction, and an exponent. Our fraction is expressed as a four-digit decimal. The exponent is a single-decimal digit. So our format is: ± f.fff x 10 ± e where:
Zero is +0.000 x 10 +0 . We represent these numbers in "E" format: ± f.fff E ± e . This format is similar to the floating-point format used in many computers. The IEEE has defined a floating-point standard (#742), but not all machines use it. Table 19-1 shows some typical floating-point numbers. Table 19-1. Floating-point examples
The floating-point operations defined in this chapter follow a rigid set of rules. To minimize errors we make use of a guard digit . That is an extra digit added to the end of the fraction during computation. Many computers use a guard digit in their floating-point units. |
| I l @ ve RuBoard |
| I l @ ve RuBoard |
19.2 Floating Addition/SubtractionTo add two numbers , such as 2.0 and 0.3, the computer must perform the following steps:
To subtract a number:
|
| I l @ ve RuBoard |
| I l @ ve RuBoard |
19.3 Multiplication and DivisionWhen we want to multiply two numbers , such as 0.12 x 11.0, the following rules apply:
Notice that in multiply, you didn't have to go through all that shifting. The rules for multiplication are a lot shorter than those for add as far as the computer hardware designers are concerned . Integer multiplication is a lot slower than integer addition. In floating point, multiplication speed is a lot closer to that of addition. To divide numbers like 100.0 by 30.0, we must perform the following steps:
|
| I l @ ve RuBoard |
|
Practical C++ Programming Authors: Oualline S. Published year: 2003 Pages: 206-208/364 |
![]() C Programming Language (2nd Edition) | ![]() C Pocket Reference | ![]() C in a Nutshell (In a Nutshell (O'Reilly)) | ![]() Mastering Algorithms with C |