CS-220 Spring 2016 Lab 3 Square Roots

Background - Calculating Square Roots

We use a square root to demonstrate the properties of floating point numbers, specifically the concept that a floating point number is an approximation of a number, and that we need to deal with the concepts of tolerances and errors.

We will be calculating a floating point square root using an iterative method which, at every iteration, increases the accuracy of the square root, and decreases the error associated with our current approximation of a square root.

For more information on the various different methods of calculating a square root, see the Wikipedia article, Methods of Computing Square Roots. For this lab, we will use one of the simplest and most effective methods of computing square roots, known as the Babylonian Method

Making some Code

Fixing the Endless Loop problem

Extending to larger Precision

How good is good enough?

Suppose you are given the North/South distance from A to B in variable NS, and the East/West distance from A to B in variable EW. Your goal is to compute the straight line distance from A to B, which can be evaluated using the formula:

dist = sqrt((NS * NS) + (EW * EW), tolerance);

You will provide this distance to your friend, who has a water balloon thrower with perfect accuracy. If NS and EW are specified in meters, and you want to throw a water balloon into a trash barrel with a 1.3 meter radius, would a tolerance of 5.0 be good enough? What about 3.0? What about 1.0? What about 0.5?

Lab Report

Download and edit the following file: lab3_report.txt. Then submit your editted file on Blackboard in the Lab 3 submission area.