CS520
Spring 2016
Programming Assignment 2
Due Wednesday February 24


Implement two functions for converting between IEEE double-precision floating-point and 64-bit two's complement integer.

The l2d routine should take one 64-bit integer as its only argument and should return a 64-bit integer. However, the return value should be interpreted to be actually an IEEE double-precision floating-point value. The return value should be the result of converting the input integer value to IEEE double-precision floating point. The conversion should be implemented using only integer operations. Be sure to handle negative input values.

The d2l routine should take one 64-bit integer as its only argument and should return a 64-bit integer. However, the input value should be interpreted to be actually an IEEE double-precision floating-point value. The return value should be the result of converting the input value to 64-bit two's complement integer. The conversion should be implemented using only integer operations. Be sure to handle negative, NaN, infinity and denormalized input floating-point values.

Your solution for this assignment should run on agate.cs.unh.edu. This machine uses the Intel implementation of IEEE floating point to convert to and from integer values. Your implementation should match the Intel hardware exactly.

The file ~cs520/public/prog2/prog2.c contains stubs for the two functions. You should complete these two functions. If you add helper functions to this file, then hide those functions by using the static keyword. Do not put a main function in this file!

You should use #if C preprocessor commands to allow your debugging prints to be easily turned on or off. For example,

#define DO_DEBUGGING_PRINTS 1

#if DO_DEBUGGING_PRINTS
  fprintf(stderr, "this is debugging output\n");
#endif
By simply changing the 1 to a 0 in the definition of DO_DEBUGGING_PRINTS, the debugging output can be disabled. You want the debugging output to be enabled for the submission of Lab 3, but be sure you disable any debugging output before you submit Lab 4 and Program 2.

Your program will be graded primarily by testing it for correct functionality:

In addition, remember, you may lose points if your program is not properly structured or adequately documented.

By the due date of the lab on Friday February 19, you should have a complete implementation of d2l. Prior to the lab, do the design, implementation and initial testing for the function. Use the lab to do the final testing of the function.

Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment.

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

Your programs should be submitted for grading from agate.cs.unh.edu. To turn in this assignment, type:
~cs520/bin/submit prog2 prog2.c

Submissions can be checked by typing:
~cs520/bin/scheck prog2

This assignment is due Wednesday February 24. The standard late policy concerning late submissions will be in effect. See the course overview webpage.

Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!


Last modified on February 4, 2016.

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