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:
double long_to_double(signed long l);
signed long double_to_long(double d);
double r1 = long_to_double(l); double r2 = (double) l; assert(r1 == r2);
long l1 = double_to_long(d); long l2 = (long) d; assert(l1 == l2);
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.
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.
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!
% ~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.