CS520
Fall 2016
Laboratory 4
Friday September 23
The lab must be submitted prior to noon on Sunday September 25.


Make your FloatAdd function handle these eight cases:

The fifth and sixth test cases will require you to support negative inputs. If both inputs are negative, then you add the significands (after aligning the exponents) and set the sign bit when encoding the result. If the inputs have different signs, then subtract the value with the smaller magnitude from the value with the larger magnitude (after aligning the exponents), and the sign of the result is the sign of the value with the larger magnitude.

The seventh and eighth test cases require you to normalize the result. In one case you will have two bits to the left of the radix point and you will need to shift right one position and add one to the exponent. In the other case you will need to shift left until the value is normalized, subtracting from the exponent the distance that you need to shift. Remember anytime you add or subtract from the exponent then you need to worry about underflow and overflow.

You will have to construct a main program to test these eight cases. But do not submit this main program! Put it in a separate file.

Note: To test the 1st, 2nd, and 5th bullet points, you cannot simply pass the floating point values to FloatAdd. You must either pass in their floating point representations in hex, or declare the test values as floats, take their addresses, cast them to int *, and then dereference so that you can pass them as ints whose bits store the floating point representation of the test values. As an example, if f1 and f2 are floats that store the values to be tested, you can call your function like this:

FloatAdd(*(int *)&f1, *(int *)&f2);

You must turn-off any debugging code before you submit your lab.

You should submit all the source code for your assignment in one file called FloatAdd.c. Be sure this file does not include a main function! And be sure to turn off the debugging output!

To turn in this laboratory, type:

% ~cs520/bin/submit lab4 FloatAdd.c

Submissions can be checked by typing:

% ~cs520/bin/scheck lab4

Remember that there are no late submissions of labs. Submit what you have prior to noon on Sunday September 25.


Last modified on August 18, 2016.

Comments and questions should be directed to pjh@cs.unh.edu