CS 3843 Computer Organization Fall 2011
Activity on IEEE Floating Point


In this activity we we start writing a program that will be able to compute the value of an IEEE floating point format number.
We will be using a format with 4 exp bits and 7 frac bits.
You will be assigned to a group and working using the following rules.
  1. Work on each step individually
  2. When you complete a step, indicate your progress using ClassQue.
  3. You may not move on to the next step until all members of the group have completed that step.
  4. When you have completed a step, help the other members of your group until all members of the group have completed that step.
  5. If you are stuck, and no members of your group are available or able to help, ask the instructor.

This activity has been divided into 8 steps.
  1. Write a main program called ieee-4-7.c that takes a single unsigned int argument and prints it value. The program should check the number of command line arguments. If it does not have exactly one argument it should print a descriptive message an exit. Otherwise it should print the value of the argument in hexadecimal. Use strtol to convert the argument to an long and then cast it to an unsiged integer. The second parameter of strtol should be NULL and the third should be 0. This will allow you to enter the argument in decimal or hex.
  2. Next we will define some constants that will be useful in the rest of the program. They should be defined at the top of the program with #define statements. The table below gives some of the constants you will need.
    namedescription
    EXPSHIFTThe number of bits to shift the exp field to get it to the low order bits.
    EXPMASKThe mask to use to isolate the exp bits after they have been shifted.
    FRACMASKThe mask to use to isolate the frac bits.
    SIGNMASKThe mask to use to isolate the sign bit. The position of the sign bit is unchanged.
    BIASThe value of the bias.
    Calculate the values of each of these before going to the next step.
  3. Write a method called getExp that takes a single unsigned int as a parameter and returns an unsigned int containing the exp bits of the corresponding number as its low order bits. Use the constants from the above table in your program. Have the main program call this function and print its return value in decimal.
    The getExp function should not do any I/O.
    Test the program with the inputs from the table at the bottom of the page.
  4. Write a method called getFrac that takes a single unsigned int as a parameter and returns an unsigned int containing the frac bits of the corresponding number. Again, print the result and do the tests from the table.
  5. Write a method called getSign that returns +1 if the sign bit of the represented number is clear and -1 if it is set. Again, print and test with the values in the table.
  6. Write the following methods that each take a single unsigned int and returns either true (1) or false (0). For a given input, exactly one of these should return true, and the other should return false.
    1. int isDenormalized(unsigned x);
    2. int isNormalized(unsigned x);
    3. int isInfinity(unsigned x);
    4. int isNAN(unsigned x);
    Test these with the values from the table.
  7. Write the following methods that each return a double value. If the parameter is of the appropriate type, it returns the value of the parameter when the low 12 bits are interrepted as an IEEE floating point number with 4 exp bits and 7 frac bits. Write these without using the pow function. You can multipy or divide by powers of 2 in a loop. (Note that you cannot do this by shifting since the values are doubles, not integers.)
    1. double getDenormalizedValue(unsigned x);
    2. double getNormalizedValue(unsigned x);
    3. double getInfinityValue(unsigned x);
    You should test each of these as you write it by using inputs from the table below.
    Now write the function:
        double getValue(unsigned x);
    that returns the value of the appropraite function above or returns a NaN. You can generate a NaN by calculating 0.0/0.0, but you may have to do this with a variable, since otherwise the compiler might complain.
  8. This step has been replaced in Assignment 3.
Test Data
inputexp fractype value
noneerror message
5003 116normaized0.11914
0x6e21398normalized113
000 denormalized0
50050 denormalized0.00610
0xa174 23normalized-0.14746
0xf8015 0infinity-inf
0xfff15127NaNnan