CS520
Spring 2016
Laboratory 4
Friday February 19
The lab must be submitted prior to noon on Sunday February 21.


This lab cannot be done in 50 minutes. Therefore, you must start this lab before coming to lab.

Complete the d2l 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 double types so that you can set up a test rigging to evaluate your function. In addition, you should use casts between pointer types to change the interpretation of bytes in memory. For example, you might construct a main function like this one:

#include <stdio.h>

long d2l(long);

int main(void)
{
  long in;
  double d;
  long l;

  in = 0x402e000000000000L;
  d = *(double *)&in;
  l = d;
  printf("%016lx (%e) --> %016lx (my result is %016lx)\n", in, d, l, d2l(in));

  return 0;
}

If the main function is in the file main.c and your implementation of d2l is in the file prog2.c, then to compile and run the program:

gcc -Wall -std=c99 prog2.c main.c -o prog2
./prog2

Also, consider generating a large number of random tests. This code will generate a 64-bit value containing random bits:

long l1 = rand();
long l2 = rand();
long testThisValue = (l1 << 32) | l2;
You will need to #include "stdlib.h". See "man rand" for more information.

You should submit all the source code for your assignment in one file called prog2.c. Be sure this file does not include a main function! And be sure to turn off the debugging output!

To turn in this laboratory, type:

% ~cs520/bin/submit lab4 prog2.c

Submissions can be checked by typing:

% ~cs520/bin/scheck lab4

Remember that there are no late submissions of labs. Submit what you have prior to noon on Sunday February 21.


Last modified on February 4, 2016.

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