• Aucun résultat trouvé

fraction with n digits, then it is also a terminating decimal fraction with n digits, since

EXERCISES

1.2-l Convert the following binary fractions to decimal fractions:

(.1100011)2 (. 1 1 1 1 1 1 1 1)2

1.2-2 Find the first 5 digits of .1 written as an octal fraction, then compute from it the first 15 digits of .1 as a binary fraction.

1.2-3 Convert the following octal fractions to decimal:

(.614)8 (.776)8

Compare with your answer in Exercise 1.2-1.

1.2-4 Find a binary number which approximates to within 10-3.

1.2-5 If we want to convert a decimal integer N to binary using Algorithm 1.1, we have to use binary arithmetic. Show how to carry out this conversion using Algorithm 1.2 and decimal arithmetic. (Hint: Divide N by the appropriate power of 2, convert the result to binary, then shift the “binary point” appropriately.)

1.2-6 If we want to convert a terminating binary fraction x to a decimal fraction using Algorithm 1.2, we have to use binary arithmetic. Show how to carry out this conversion using Algorithm 1.1 and decimal arithmetic.

1.3 FLOATING-POINT ARITHMETIC

Scientific calculations are usually carried out An n-digit floating-point number in base

in floating-point has the form

arithmetic.

(1.5)

where is a called the mantissa, and e is an

integer called the exponent. Such a floating-point number is said to be normalized in case or else

For most computers, although on some, and in hand calculations and on most desk and pocket calculators,

The precision or length n of floating-point numbers on any particular computer is usually determined by the word length of the computer and may therefore vary widely (see Fig. 1.1). Computing systems which accept FORTRAN programs are expected to provide floating-point numbers of two different lengths, one roughly double the other. The shorter one, called single precision, is ordinarily used unless the other, called double precision, is specifically asked for. Calculation in double precision usually doubles the storage requirements and more than doubles running time as compared with single precision.

Figure 1.1 Floating-point characteristics.

The exponent e is limited to a range

(1.6) for certain integers m and M. Usually, m = - M, but the limits may vary widely; see Fig. 1.1.

There are two commonly used ways of translating a given real number x into an n floating-point number fl(x), rounding and chopping. In rounding, fl(x) is chosen as the normalized floating-point number nearest x; some special rule, such as symmetric rounding (rounding to an even digit), is used in case of a tie. In chopping, fl(x) is chosen as the nearest normalized floating-point number between x and 0. If, for example, two-decimal-digit floating-point numbers are used, then

and

On some computers, this definition of fl(x) is modified in case (underflow), where m and M are the bounds on the exponents; either fl(x) is not defined in this case, causing a stop, or else fl(x) is represented by a special number which is not subject to the usual rules of arithmetic when combined with ordinary floating-point numbers.

The difference between x and fl(x) is called the round-off error. The round-off error depends on the size of x and is therefore best measured relative to x. For if we write

(1.7) where is some number depending on x, then it is possible to bound independently of x, at least as long as x causes no overflow or underflow. For such an x, it is not difficult to show that

in rounding (1.8)

while in chopping (1.9)

1.3 FLOATING-POINT ARITHMETIC 9 See Exercise 1.3-3. The maximum possible value for is often called the unit roundoff and is denoted by u.

When an arithmetic operation is applied to two floating-point num-bers, the result usually fails to be a floating-point number of the same length. If, for example, we deal with two-decimal-digit numbers and then

Hence, if denotes one of the arithmetic operations (addition, subtraction, multiplication, or division) and denotes the floating-point operation of the same name provided by the computer, then, however the computer may arrive at the result for two given floating-point numbers x and y, we can be sure that usually

Although the floating-point operation corresponding to may vary in some details from machine to machine, is usually constructed so that

(1.10) In words, the floating-point sum (difference, product, or quotient) of two floating-point numbers usually equals the floating-point number which represents the exact sum (difference, product, or quotient) of the two numbers. Hence (unless overflow or underflow occurs) we have

(1.11 a) where u is the unit roundoff.

use the equivalent formula

In certain situations, it is more convenient to (1.116) Equation (1.11) expresses the basic idea of backward error analysis (see J.

H. Wilkinson [24]†). Explicitly, Eq. (1.11) allows one to interpret a float-ing-point result as the result of the corresponding ordinary arithmetic, but performed on slightly perturbed data. In this way, the analysis of the effect of floating-point arithmetic can be carried out in terms of ordinary arithmetic.

For example, the value of the function at a point x0 can be calculated by n squarings, i.e., by carrying out the sequence of steps

with In floating-point arithmetic, ing to Eq. (1.1 la), the sequence of numbers

we compute instead,

accord-†Numbers in brackets refer to items in the references at the end of the book.

with all i. The computed answer is, therefore,

To simplify this expression, we observe that, if then

for some (see Exercise 1.3-6). Also then

for some Consequently,

for some In words, the computed value is the

exact value of f(x) at the perturbed argument

We can now gauge the effect which the use of floating-point arithmetic has had on the accuracy of the computed value for f(x0) by studying how the value of the (exactly computed) function f(x) changes when the argument x is perturbed, as is done in the next section. Further, we note that this error is, in our example, comparable to the error due to the fact that we had to convert the initial datum x0 to a floating-point number to begin with.

As a second example, of particular interest in Chap. 4, consider calculation of the number s from the equation

(1.12) by the formula

If we obtain s through the steps

then the satisfy

corresponding numbers computed in floating-point arithmetic

Here, we have used Eqs. (1.11a ) and (1.11b), and have not bothered to

1.3 FLOATING-POINT ARITHMETIC 11 distinguish the various by subscripts. Consequently,

This shows that the computed value for s satisfies the perturbed equation

(1.13) Note that we can reduce all exponents by 1 in case ar+1 = 1, that is, in case the last division need not be carried out.

EXERCISES

1.3-1 The following numbers are given in a decimal computer with a four-digit normalized mantissa:

Perform the following operations, and indicate the error in the result, assuming symmetric rounding:

1.3-2 Let be given by chopping. Show that and that (unless overflow or underflow occurs).

13-3 Let be given by chopping and let be such that (If

Show that then is bounded as in (1.9).

1.3-4 Give examples to show that most of the laws of arithmetic fail to hold for floating-point arithmetic. (Hint: Try laws involving three operands.)

1.3-5 Write a FORTRAN FUNCTION FL(X) which returns the value of the n-decimal-digit floating-point number derived from X by rounding. Take n to be 4 and check your calculations in Exercise 1.3-l. [Use ALOG10(ABS(X)) to determine e such that

1.3-6 Let Show that for all there exists o

that Show also that for

s o m e provided all have the same sign.

1.3-7 Carry out a backward error analysis for the calculation of the scalar product Redo the analysis under the assumption that double-precision ac-cumulation is used. This means that the double-precision results of each multiplicatioin are retained and added to the sum in double precision, with the resulting sum rounded only at the end to single precision.