CSC 336 H1F Assignment One

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (4 votes)

1. (a) In IEEE arithmetic how many double precision numbers are there between any two adjacent
nonzero single precision numbers? Justify your response.
(b) What is the largest integer p such that all integers in the interval [−p, p] are exactly representable
in IEEE double precision arithmetic? What is the corresponding p for IEEE single precision
arithmetic? Justify your responses.
2. (a) The following C program:
#include <stdio.h>
int main (void)
{
double a, b;
for (a = 0.1; a <= 0.5; a += 0.1)
printf(“a = %e\n”, a);
for (b = 1.1; b <= 1.5; b += 0.1)
printf(“b = %e\n”, b);
return 0;
}
outputs five values of a and four values of b. Explain why the two loops do not produce the
same number of lines of output.
(Ask for assistance if you do not know C. The programming language is not the issue here.)
(b) Suppose that you are writing a program to run on a computer that supports IEEE floating
point arithmetic, have declared and initialize a floating point variable named x, and need to
determine 10% of the value stored in x. You need to decide between using the expression
0.1 * x or x / 10.0. Which of these two expressions would you recommend using if accuracy
of the final result is your biggest concern? Explain.
Dept. of Computer Science, University of Toronto, St. George Campus Page 1 of 2
CSC 336 H1F Assignment One Fall 2015
3. You know that cos( 2mπ ) = 1 for every integer m. Using a programming language of your choice that
uses IEEE fixed precision floating-point arithmetic, write a program that calculates cos( 2*m*pi )
for m = 10.0
k
, k = 0, 1, 2, . . . , 20, where pi is either your language’s builtin approximation to π or
4.0*arctan(1.0). Present the results of your calculations in a formatted table, with column headings
for the values of k, 2*m*pi, and cos( 2*m*pi ). Use a “scientific notation” to present the values of
2*m*pi and cos( 2*m*pi ), giving 15 significant figures for both 2*m*pi and cos( 2*m*pi ).
Carefully explain why you do not always compute cos(2*m*pi) ≈ 1.0 and why the approximations
change significantly for larger values of k .
4. Consider the problem of evaluating the function f(x) for any x ∈ [−π/2, +π/2], where
f(x) =



1 − cos(x)
sin(x)
, x ∈ [−π/2, 0) ∪ (0, +π/2]
0, x = 0.
(a) Show why one can expect to be able to write a computer program that uses floating-point
arithmetic to accurately evaluate f(x) at any x ∈ [−π/2, +π/2].
(b) Derive an accurate algorithm for evaluating f(x) and explain why you think that accurate
results will be computed. Make use of standard math library functions like sin() and cos()
when expressing your algorithm.
If you have questions or encounter any difficulties, post a description of the issue on the Piazza course
forum.
Dept. of Computer Science, University of Toronto, St. George Campus Page 2 of 2