Docsity

Quiz 1 for AMSC/CMSC 460, Fall 2007: Floating Point Computations - Prof. Dianne P. O'Leary, Quizzes of Computer Science

Toggle sidebar
bg1
AMSC/CMSC 460 Quiz 1 ,Fall 2007
For this page of the quiz, assume you have a base 2 computer that stores
floating point numbers using a 5 bit normalized mantissa (x.xxxx), a 4 bit
exponent, and a sign for each. Assume that all numbers are chopped rather
than rounded.
1. (10) Consider the the following code fragment:
x = 1;
for j=1:2^ (20),
x = x + delta;
end
For the computer specified above, what is the largest value of delta for which
the final value of xis 1? Explain your reasoning.
Answer: Since this machine only stores 5 bits, the machine number just
greater than 1 is 1.00012= 1 + 1/16.
In the first iteration of the loop, if delta = 1/16, then xwill change from 1
to 1.00012.
If delta is any number between 0 and 1/16, then (because of chopping), x
will not change its value.
So xis constant for any positive number less than 1/16.
The largest machine-representable number less than 1/16 is
1.11112×2−5= 2−5(1 + 1/2 + 1/4 + 1/8 + 1/16) = 1/16 −1/512.
1
pf2

Partial preview of the text

Download Quiz 1 for AMSC/CMSC 460, Fall 2007: Floating Point Computations - Prof. Dianne P. O'Leary and more Quizzes Computer Science in PDF only on Docsity!

AMSC/CMSC 460 Quiz 1 , Fall 2007

For this page of the quiz, assume you have a base 2 computer that stores floating point numbers using a 5 bit normalized mantissa (x.xxxx), a 4 bit exponent, and a sign for each. Assume that all numbers are chopped rather than rounded.

  1. (10) Consider the the following code fragment:

x = 1; for j=1:2^ (20), x = x + delta; end

For the computer specified above, what is the largest value of delta for which the final value of x is 1? Explain your reasoning.

Answer: Since this machine only stores 5 bits, the machine number just greater than 1 is 1. 00012 = 1 + 1/16.

In the first iteration of the loop, if delta = 1/16, then x will change from 1 to 1. 00012.

If delta is any number between 0 and 1/16, then (because of chopping), x will not change its value.

So x is constant for any positive number less than 1/16.

The largest machine-representable number less than 1/16 is

  1. 11112 × 2 −^5 = 2−^5 (1 + 1/2 + 1/4 + 1/8 + 1/16) = 1/ 16 − 1 / 512.
  1. Consider the equation x^2 − .81 = 0.

(a) (5) What is the relative error in the values x 1 = .85, x 2 = −.85 as approximations to the two solutions to the equation?

Answer: The two relative errors are equal: ∣ ∣ ∣ ∣

∣ =^

(b) (5) Give a backward error bound for x 1 = .91, x 2 = −.91 as approxima- tions to the two solutions to the equation.

Answer: For backward error, we report a bound on the distance between the problem we solved and the problem we wanted to solve. We have solved the problem x^2 − (.91)^2 = 0,

when we wanted to solve the problem

x^2 − .81 = 0,

so we have changed the constant term in the polynomial by

. 81 − (.91)^2.