HP-UX Floating-Point Guide
Chapter 3 89
Factors that Affect the Results of Floating-Point Computations
Floating-Point Coding Practices that Affect Application Results
Figure 3-2 Adding Values with Very Different Magnitudes
In fact, if the difference between the exponents of two single-precision
values is 25 or greater, the smaller value is right-shifted out of existence,
and adding the two values results in no change at all in the larger value.
For example, consider a criminally minded American bank employee who
arranges to have a penny transferred to his or her own account every so
often. If the bank’s computer uses single-precision floating-point
arithmetic, and if the account starts with a balance of zero, then after
almost twenty-three million transfers, when the bank account reaches
$262,144.00, it will suddenly stop growing. Well before then, the
employee may notice irregularities due to rounding errors. After 5
million transfers, the account will have more than 5 million pennies in it;
but after 15 million transfers, it will have fewer than 14 million pennies.
The larcenous employee may become frustrated with the bank’s
computer system, but it is behaving perfectly properly. (This irregularity
is the reason why bank computers use COBOL’s fixed-point arithmetic,
not floating-point.)
The following example makes the same point more simply. It
accumulates a sum by adding 0.01 to the starting value a thousand
times, in single-precision, and then subtracting it.