CS520
Spring 2018
Program 2
Due 12noon, Wednesday February 21


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. When 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:

Thorough testing will be required on this assignment in order to get full credit. In particular, you should use exhaustive testing for s2d. The grading of the 10% categories will be all or nothing: if you pass all the tests in the category you will get the 10%; if you don't you will get 0%.

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. You should apply the principles of problem decomposition, incremental development and incremental testing. Do not submit one monolithic function!

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 at 12noon on Wednesday February 21. 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 January 23, 2018.

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