Write a c program that will determine the value of a number


In this assignment you will write a C program that will determine the value of a number in an IEEE-like floating point format.

Follow the Programming Guidelines.

For this assignment, do not use the pow or similar functions. All powers of two must be calculated by shifts or loops.

Part 1:

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.

  1. You will work in a group of two or three (at most) students
  2. 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 7 steps.

  1. Create a directory called ieee-activity-firstname1-fairstname2 and copy all of the files from ~muzahid/ieee-activity into that directory:
       cp ~muzahid/ieee-activity/* .
    Modify the main program so that it prints name of the group members instead of mine.
    The main program takes a single unsigned int argument and prints it value. 
    Understand what the main program and makefile do and then compile and run the program.
    Once the assignment is done, you will copy your folder to ~muzahid/ieee-activity/submission/
       cp -r ./ieee-activity-firstname1-firstname2 ~muzahid/ieee-activity/submission/ 
       chmod -R ugo+rwx ~muzahid/ieee-activity/submission/ieee-activity-firstname1-firstname2/ 
  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 ieee-4-7.h.
    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 and put them in ieee-4-7.h 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.
    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, 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, 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 interpreted as an IEEE floating point number with 4 exp bits and 7 frac bits.
    Write these without using the pow function.
    You can multiply 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 getValueDenormalized(unsigned x);
    2. double getValueNormalized(unsigned x);
    3. double getValueInfinity(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 appropriate 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.

When you have finished the 7 steps of the activity do the following:

Step 8:

Instead of using ieee-4-7.c use ieee-4-7-new.c provided in the same folder (i.e., /home/muzahid/ieee-activity of any elk machine).

Compile by using command "make". It creates a new executable ieee-4-7-new.

Run the program with no parameters. It should create a file called tests-4-7.out.

Check that the first 7 lines of the file are correct, and execute:

wc tests-4-7.out

md5sum tests-4-7.out

and save the results.

Save the first 10 lines of tests-4-7.out in a file along with the output from running wc and md5sum above.

Include this with your source code and hand in the hard copy.

Do not print out the entire tests-4-7.out file.

Part 2:

Do not start this until you have Part 1 completely working.

Make a new directory: assign2 for this part. Create this directory inside the original directory that you created for Part 1. Copy all of the files from Part 1 into this directory.

Rename ieee-4-7-library.c, ieee-4-7.h, and ieee-4-7.c to ieee-library.c, ieee.h, and ieee.c.

Modify all of the functions you wrote so that they take 2 extra unsigned parameters at the end, the number of exp bits, and the number of frac bits.

Remove the defines from ieee.h. The functions should use these extra parameters instead of the constants.

Do not use global variables to solve this problem.

Modify the main program so that it takes 3 command line parameters instead of one.

The first parameter is the number of exp bits and the second is the number of frac bits.

The third parameter is the value to be converted.

Your program can assume that the values of the first two parameters are greater than 0 and sum to a number less than 32.

Make other modifications as needed. Replace the function createDataFile with this one.

It should create a file called tests-5-8.out.

Check that the first 7 lines of the file are correct, and execute:

wc tests-5-8.out

md5sum tests-5-8.out

and save the results.

Save the first 10 lines of tests-5-8.out in a file along with the output from running wc and md5sum above.

Include this with your source file and hand in the hard copy.

Do not print out the entire tests-5-8.out file.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a c program that will determine the value of a number
Reference No:- TGS01291837

Expected delivery within 24 Hours