CS520
Spring 2019
Program 2
Due 12noon, Wednesday February 20


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

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

The f2i routine should take one 32-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 single-precision floating-point value. The return value should be the result of converting the input value to 32-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.

You should use the the standard header files stdint.h and inttypes.h. These header files define size-specific integer types (e.g. int32_t) and portable printf formats for those types (e.g. PRIx32). For example: int32_t x; printf("x is %" PRId32 "\n", x); <\kbd>

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. You should submit all the source code for your assignment in this file.

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

The grading for each function will be all or nothing. If you pass all the tests for the function you will get full credit; if you don't you will get 0 points for that function. So test your functions exhaustively.

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

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 program 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 at 12noon on Wednesday February 20. 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 15, 2019.

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