Do an initial implementation of the f2i function described in the Program 2 specification.
To test your function, you will need to supply a main function. Put this function in another file! In this main function you may use float types so that you can set up a test rigging to evaluate your function. In addition, you should use a union to change the interpretation of bytes in memory. For example, you might construct a main function like this one:
#include <stdio.h> #include <stdint.h> #include <inttypes.h> int32_t f2i(uint32_t); union { uint32_t i; float f; } u; int main(void) { uint32_t in; int32_t i; in = 0x4D2AAAAA; u.i = in; i = u.f; printf("%08" PRIx32 " (%e) --> %08" PRIx32 " (my result is %08" PRIx32 ")\n", in, u.f, i, f2i(in)); return 0; }
If the main function is in the file main.c and your implementation of f2i is in the file prog2.c, then to compile and run the program:
gcc -Wall -std=c99 prog2.c main.c -o lab3 ./lab3
This lab will be tested using only the following inputs to f2i:
You should submit all the source code for your lab in one file called prog2.c. Be sure this file does not include a main function!
To turn in this laboratory, type:
% ~cs520/bin/submit lab3 prog2.c
Submissions can be checked by typing:
% ~cs520/bin/scheck lab3
Remember that there are no late submissions of labs. Submit what you have prior to 12noon on Sunday February 10. Be careful: one minute late is late.
Comments and questions should be directed to pjh@cs.unh.edu