Part 0: Preparation (0 points)
|
Part 1: Naive implementation
(3 points)
|
The file RAT.h is the inteface. It lists
the functions that your client program can use.
The file RATtest.c is a sample client
program that uses the inteface functions to perform rational
arithmetic.
Your first task
is to write an implementation file RAT.c,
that implements the functions described in RAT.h
so that client programs like RATtest.c can use it
as a black box.
Part 2: Client (3 points)
|
In this part you will write a client program e.c
that computes a rational approximation to the mathematical
constant e using the Taylor
expansion e = 1/0! + 1/1! + 1/2! + 1/3! + . . .
Part 3: Improved implementation
(3 points)
|
In this part you will write a better version of the
RAT.c implementation that you wrote in Part 1.
The goal here is to stave off overflow by being a bit more
clever.
Submission and readme (1 point)
|
There are many ways to compute pi, but the continued fraction
expansion given in the course packet appears to be one of the
simples and most useful for getting a good rational approximation.
arctan(x) = x
---------------------
1 + x^2
----------
3 + (2x)^2
---------
5 + (3x)^2
--------
...
There are other ways to compute rational approximations to
e and pi. The following are accurate to an amazing 16 decimal places:
e = 28245729/10391023, pi = 245850922/78256779.
There are lots of
interesting Web sites on pi
including
computing the value of pi and a
history of pi calculations.
Kevin Wayne