CS520
Fall 2013
Program 2
Due Sunday September 22


Write two functions to convert a signed long to a double precision floating point and a double precision floating points to signed long. Unlike the last program, this program will not be a standalone binary, but will instead act more like a library, providing the two functions for use in other programs. There are two functions you must implement:

Each function should do the same thing as a cast statement. That is:

Files

I provide 4 files:
  1. makefile: a Makefile
  2. convert_main.c: Main file for the program
  3. convert.c: A c file with stub functions you will need to implement
  4. convert.h: A header file for the stub functions
The makefile is for students who would like to use the make tool to build their program. If you have never used make before, it is a useful tool for building (and re-building) programs. Here is a simple example of me using make to build some binaries, and then running one of the binaries. Clearly, my program needs some work, because neither of the two outputs match.
cmw@paris:~/cs520/website/files/prog2$ ls
convert.c  convert.h  convert_main.c  makefile
cmw@paris:~/cs520/website/files/prog2$ make
gcc -Wall -std=c99 convert_main.c -c -o convert_main.o
gcc -Wall -std=c99 convert.c -c -o convert.o
gcc  convert_main.o convert.o -o convert_number
gcc -g  convert_main.o convert.o -o convert_number_debug
cmw@paris:~/cs520/website/files/prog2$ ls
convert.c  convert_main.c  convert_number        convert.o
convert.h  convert_main.o  convert_number_debug  makefile
cmw@paris:~/cs520/website/files/prog2$ ./convert_number
Should be 1.000000: 0                                    <--- not good
Should be 4: 0.000000                                    <--- not good
cmw@paris:~/cs520/website/files/prog2$ 

The program itself should be written in the convert.c. I have already put stubs that work incorrectly in the convert.c file, which you will need to fix. My stubs both simply return 0, which is obviously incorrect.

Testing

The convert_main.c is a simple example of a program that is going to use the functions you are going to write. In order to do a good job testing this program, you will need to consider more sophisticated cases. The good news, regarding this program, is you can quite easily check any output by simply doing the cast, and comparing the result of the cast to the output of your function.

Students should not look at one another's code for doing the actual conversion, but I do not have a problem with students working together to come up with better replacements for the simple convert_main.c program that I am distributing. Students are free to share the content of convert_main.c with one another, as long as you keep the separation into files that I began, with the implementation of the two conversion functions in one file, and those functions getting used and called in convert_main.c.


Grading

Your program will be graded primarily by testing it for correct functionality.
  1. Do not do a cast and return the result, that is not allowed, and will result in getting a 0.
  2. 30 points will be awarded for correctly converting doubles to longs.
  3. 30 points will be awarded for correctly converting longs into doubles where the long does not require rounding.
  4. 30 additional points will be awarded for correctly rounding longs that cannot fit precisely into a double.
  5. 10 points will be awarded for handling different error cases and overflow cases.

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.

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

Remember: as always you are expected to do your own work on this assignment. Copying code from another student (other than specifically mentioned in these instructions) or from sites on the internet is explicitly forbidden!

Submission

Your programs should be submitted for grading from agate.cs.unh.edu. To turn in this program, type:
% ~cs520/bin/DoSubmission.py prog2 convert.c

This submission script is new. It passed what testing I have done on it, but it may still have issues. If there are any problems, please contact me via email and I will do my best to assist you. If I cannot be reached, please send me a copy of your assignment via email, and we will deal with the submission script later.

Due Date

This assignment is due Sunday September 22. The standard late policy concerning late submissions will be in effect.