Docsity

Floating-Point Arithmetic: Normalization, IEEE Precision, and Error Analysis, Papers of Mathematics

Toggle sidebar
bg1
In-class exercises, Sept. 25
Due on Tuesday, Oct. 1 on plain old paper.
Binary floating-point numbers have the form
ˆx=±a0.a1a2···ad×2e.
If ˆx6=0, then ˆxis normalized if a0=1. Normalization makes eunique, since it
must be the largest integer such that 2e≤ |ˆx|. If ˆx=0, then we may simply define
the normalized representation to be 0 ×20. In IEEE single-precision arithmetic,
d=23 (i.e., 24-bit precision), and in double-precision arithmetic, d=52 (i.e.,
53-bit precision).
Floating-point arithmetic is correctly rounded if the operation ˆxˆyis per-
formed as though infinite precision were available, followed by rounding. Here
refers to the rounded floating-point operations of addition, subtraction, multiplica-
tion, and division. All four elementary operations in IEEE arithmetic are correctly
rounded, as is the square root operation. In lecture, we discussed the following
theorem:
Let ˆxand ˆybe floating-point numbers of the same precision and range.
Suppose that ˆx·ˆyis defined and representable, where ·refers to one
of addition, subtraction, multiplication, or division. Let ˆxˆydenote
the corresponding correctly-rounded result (to the same precision as
ˆxand ˆy). Then there is a real number δsuch that
ˆxˆy= ( ˆx·ˆy)(1+δ),(1)
where |δ|≤ε(the machine epsilon) in all rounding modes and where
|δ| ≤ 1
2εwhen rounding to nearest.
By defined and representable, we mean that ˆx·ˆyis a real number (e.g., we aren’t
dividing by 0) and can be approximated as a floating-point number without over-
flow or underflow.
1. Consider IEEE single precision.
(a) Show that the values 1.0, 2.0, and 3.0 can be represented exactly.
(b) You can extend your argument in (a) to show that 4.0, 5.0, 6.0, . . . , M
have exact representations. What is M?
(c) Repeat your calculation in (b) for IEEE double precision.
1
pf2

Partial preview of the text

Download Floating-Point Arithmetic: Normalization, IEEE Precision, and Error Analysis and more Papers Mathematics in PDF only on Docsity!

In-class exercises, Sept. 25

Due on Tuesday, Oct. 1 on plain old paper. Binary floating-point numbers have the form

xˆ = ±a 0 .a 1 a 2 · · · ad × 2 e.

If ˆx 6 = 0, then ˆx is normalized if a 0 = 1. Normalization makes e unique, since it must be the largest integer such that 2e^ ≤ | xˆ|. If ˆx = 0, then we may simply define the normalized representation to be 0 × 20. In IEEE single-precision arithmetic, d = 23 (i.e., 24-bit precision), and in double-precision arithmetic, d = 52 (i.e., 53-bit precision). Floating-point arithmetic is correctly rounded if the operation ˆx yˆ is per- formed as though infinite precision were available, followed by rounding. Here refers to the rounded floating-point operations of addition, subtraction, multiplica- tion, and division. All four elementary operations in IEEE arithmetic are correctly rounded, as is the square root operation. In lecture, we discussed the following theorem:

Let ˆx and ˆy be floating-point numbers of the same precision and range. Suppose that ˆx · yˆ is defined and representable, where · refers to one of addition, subtraction, multiplication, or division. Let ˆx yˆ denote the corresponding correctly-rounded result (to the same precision as xˆ and ˆy). Then there is a real number δ such that

xˆ yˆ = ( xˆ · yˆ)( 1 + δ ), (1)

where |δ | ≤ ε (the machine epsilon) in all rounding modes and where |δ | ≤ 12 ε when rounding to nearest.

By defined and representable, we mean that ˆx · yˆ is a real number (e.g., we aren’t dividing by 0) and can be approximated as a floating-point number without over- flow or underflow.

  1. Consider IEEE single precision.

(a) Show that the values 1.0, 2.0, and 3.0 can be represented exactly. (b) You can extend your argument in (a) to show that 4.0, 5.0, 6.0,... , M have exact representations. What is M? (c) Repeat your calculation in (b) for IEEE double precision.

  1. Show that the above theorem can be restated in the following terms: In correctly rounded arithmetic, the relative error in the operation ˆx yˆ never exceeds ε in any rounding mode and never exceeds ε/2 when rounding to nearest.
  2. Although the theorem is the best that one can do with floating-point arith- metic of fixed precision and range, rounding errors can accumulate in a chain of calculations. Catastrophic cancelation occurs when two floating- point numbers, each of which is the result of a chain of computations and is of comparable size, are subtracted. In this case, the most significant dig- its disappear and expose the effects of previous roundings. Consider the quadratic formula:

r± =

−b ± D 2 a

, where D =

b^2 − 4 ac. (2)

What is the relative error in r+ in terms of the machine epsilon in 6-digit, correctly-rounded decimal arithmetic, when a = 0 .414235, b = 12, and c = 0 .0129134? Use Python, Maple, or a pocket calculator. Round the result of each cal- culation to the nearest 6-digit floating-point number before continuing to the next one. (You’re trying to simulate the behavior of a computer whose registers hold 6-digit decimal values.) For instance, you can compute

4 ⊗ a |= x 1 x 1 ⊗ c |= x 2 b ⊗ b |= x 3 x 3 x 2 |= x 4 ,

and so on. Here |= refers to the truncation to 6 digits by rounding to nearest.

  1. (a) Show that

r± =

2 c −b ±

b^2 − 4 ac

is equivalent to the usual quadratic formula for the zeroes of the polynomial ax^2 + bx + c. (b) Repeat the previous problem using Eq. (3). Which of the two equations produces the most accurate value of r+? r−? Explain why. (Hint: where does catastrophic cancelation occur?)