[MSOE Homepage]

Dr. Taylor's MSOE Homepage

Unix is a Four
Letter Word

My Photo Album

My Personal Homepage

CS-381 Main page

CS-381 -- Lab 1: Floating Point Errors

Fall Quarter 1999



Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor

S-331, 277-7339

www.msoe.edu/~taylor/

Purpose

The purpose of this lab assignment is to expose a number of potential error sources related to numerical computation.

Assignment

The number represented by pi is the ratio of the circumference of a circle to its diameter. The first known notion of its value dates back to the Egyptian Rhind Papyrus. Since then, numerous methods have been proposed for calculating pi. In the seventeenth century, James Gregory developed the following equation to approximate pi.

pi = 4 - 4/3 + 4/5 - 4/7 + ...

Those interested in reading more about pi may find that these links will keep them busy for days. Please don't forget to do your assignment though.

In this lab, you are to do the following:

  1. Design and implement a program that calculates pi according to the equation given above.
  2. Your program is required to calculate pi in the following way:
    • Create an array of two-hundred-fifty-thousand doubles.
    • Each element in the array should represent one of the terms in the equation given.
    • Use floats to calculate pi.
    • Calculate pi by summing the terms in the array
      1. from beginning to end and
      2. from end to beginning.
    • Output the results of the two calculations to the console or to a data file.
  3. Answer the following questions in your lab report:
    • What sources of errors may prevent the calculated values of pi to differ from its actual value?
    • Does the order in which the terms are summed affect the result?
    • In which order should the terms be summed in order to reduce the error? Why?

Lab report (due 4:30pm Tuesday, September 21, 1999)

The lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report. Your report should include:

  • Purpose
  • Problem Statement
  • Procedure -- what approach you used to solve the problem
  • Documented source code (you may wish to include this at the end of your report)
  • Discussion (include your program output, any problems you encountered, answers to the above questions, etc...)
  • Conclusions (what you learned, suggestions of how the lab could be improved, things you would have done differently, etc.)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic Submission Guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

If you have any questions, consult the instructor.


This page was created by Dr. Christopher C. Taylor, copyright 1999.