CS520
Spring 2015
Program 2
Due Sunday February 22


Implement two functions for converting between IEEE single-precision floating point and IEEE double-precision floating point.

The s2d routine should take one 32-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 single-precision floating-point value and 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 IEEE single-precision floating-point value to IEEE double-precision floating point. The conversion should be implemented using only integer operations.

The d2s routine should take one 64-bit integer as its only argument and should return a 32-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 IEEE single-precision floating point. The conversion should be implemented using only integer operations.

In both functions, 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 single-precision and double-precision values. Your implementation should match the Intel hardware exactly.

The files s2d.c and d2s.c in ~cs520/public/prog2 contain stubs for the two functions. You should complete these two functions. If you add helper functions to these files, then hide those functions by using the static keyword.

The ~cs520/public/prog2 directory also contains a simple test rigging for testing s2d in the file testS2D.c. There is also a stub for a test rigging for d2s in the file testD2S.c. Finally, there is a Makefile for compiling the functions and building the two test programs: testS2D and testD2S.

The public files illustrate the use of the standard header files stdint.h and inttypes.h. These header files define size-specific integer types (e.g. uint32_t) and portable printf formats for those types (e.g. PRIx32). You should use these facilities in your Program 2 code.

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. Coding guidelines are given on the course overview webpage. I also want to see that you applied the principles of problem decomposition, incremental development and incremental testing. Leave your debugging output in your code, but disabled, when you do your final assignment submission.

The goal of the lab on Monday February 9 is for you to have an initial implementation of s2d. Prior to the lab, do a design for the function. In particular, decompose the problem. I will want to see debugging output to stderr that will display for an input its three basic components: sign, exponent and fraction. And I will want to see debugging output to stderr categorizing an input as infinity, NaN, denormalized value, or "regular" value.

The goal of the lab on Monday February 16 is for you to have a complete implementation of s2d and an initial implementation of d2s. When grading this lab, I will thoroughly test your s2d function as well as do initial tests on d2s. You will want to decompose the problem when designing a solution for d2s. I will want to see debugging output to stderr that will display for an input its three basic components: sign, exponent and fraction. And I will want to see debugging output to stderr categorizing an input as infinity, NaN, denormalized value, or "regular" value.

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 Labs 3 and 4, but be sure you disable any debugging output before you submit Program 2.

Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment. Your programs will be compiled using these gcc flags: -g -Wall -std=c99.

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

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

This assignment is due Sunday February 22. 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 8, 2015.

Comments and questions should be directed to hatcher@unh.edu