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.
- Work on each step individually
- When you complete a step, indicate your progress using ClassQue.
- You may not move on to the next step until all members of the group
have completed that step.
- When you have completed a step, help the other members of your group
until all members of the group have completed that step.
- 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.
- 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.
- 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.
name | description |
EXPSHIFT | The number of bits to shift the exp
field to get it to the low order bits. |
EXPMASK | The mask to use to isolate the exp
bits after they have been shifted. |
FRACMASK | The mask to use to isolate the frac
bits. |
SIGNMASK | The mask to use to isolate the sign bit.
The position of the sign bit is unchanged. |
BIAS | The value of the bias. |
Calculate the values of each of these before going to the next step.
- 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.
- 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.
- 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.
- 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.
- int isDenormalized(unsigned x);
- int isNormalized(unsigned x);
- int isInfinity(unsigned x);
- int isNAN(unsigned x);
Test these with the values from the table.
- 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.)
- double getDenormalizedValue(unsigned x);
- double getNormalizedValue(unsigned x);
- 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.
- This step has been replaced in Assignment 3.
Test Data
input | exp |
frac | type |
value |
none | error message |
500 | 3 |
116 | normaized | 0.11914 |
0x6e2 | 13 | 98 | normalized | 113 |
0 | 0 | 0 |
denormalized | 0 |
50 | 0 | 50 |
denormalized | 0.00610 |
0xa17 | 4 |
23 | normalized | -0.14746 |
0xf80 | 15 |
0 | infinity | -inf |
0xfff | 15 | 127 | NaN | nan |