CS520
Spring 2016
Laboratory 3
Friday February 12
The lab must be submitted prior to noon on Sunday February 14.


The tasks for this lab are to edit the file prog2.c available on agate in ~cs520/public/prog2:

  1. (60 points) Write code to break out the three components of an input to d2l: sign, exponent and fraction. Insert debugging code to display these three components in hex on a single line to stderr. For example:
    sign: 1; exponent: 6A3; fraction: 0F563AB5189CD.
    
    Just show the bits for each component using hex. Do not un-bias the exponent or insert the hidden 1 bit into the fraction. Display the leading zeroes for each component, so always print one hex digit for the sign, three hex digits for the exponent, and thirteen hex digits for the fraction.

  2. (40 points) Write code to categorize an input to d2l as either zero, infinity, NaN, denormalized value, or a "regular" normalized value. Insert debugging code to display this categorization on a line by itself to stderr. Simply print "zero", "infinity", "NaN", "denormalized" or "regular".

To test your function, you will need to supply a main function. Put this function in another file! For example, you might construct a main function like this one:
#include <stdio.h>

long d2l(long);

int main(void)
{
  long in;

  in = 0x402e000000000000L;
  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

Turn in this laboratory, by typing:

% ~cs520/bin/submit lab3 prog2.c

Submissions can be checked by typing:

% ~cs520/bin/scheck lab3

Use #if C preprocessor commands to control whether the debugging prints are enabled. (See the Program 2 specification for more information about how to do this.) Leave the debugging prints enabled for your submission of this lab.

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


Last modified on February 4, 2016.

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