Question: Need help with C programming. write code to do allowing you to store these smaller floating point numbers in a 32-bit integer. INPUT: you will
Need help with C programming. write code to do allowing you to store these smaller floating point numbers in a 32-bit integer. INPUT: you will read in a program and call your functions to implement these programs. An example of one of these programs is: x = 18.113 print x y = 4.5 a = x + y print a z = x * y print z OUTPUT: The output will be the current values of the given variables at the print statements. For the above program, output would be: x = 18.0937500000 a = 22.5937500000 z = 81.2500000000 Some of this task is already done for you. I will provide a program that reads in the given programs, saves the variable values and calls the functions (described next) that you will be implementing. You are going to implement a 15 bit floating point representation, where 5 bits are for the exponent and 9 are for the fraction. Using bit level operators,write functions (shown below) to help implement the program. Assignment statement (variable = value) calls your function computeFP(), which converts from a C float value to our mini-float representation (which only uses the 15 lowest of the given 32 bits). int computeFP(float val) { } // input: float value to be represented // output: integer version in our representation o Given the number of bits, the rounding you will have to do for this representation is pretty substantial. For this assignment, we are always going to take the easy way and truncate the fraction (i.e. round down). For example, the closest representable value for 18.113 (rounding down) is 18.0937, as can be seen in the program output. Print statement (print variable) uses your getFP() function to convert from our mini-float representation to a regular C float value, and formats/prints it out nicely. float getFP(int val) { } // Using the defined representation, compute and // return the floating point value Add statement for this statement, you are going to take two values in our representation and use the same technique as described in class/comments to add these values and return the result in our representation. int addVals(int source1, int source2) {} Multiply statement for this statement, you are going to take two values in our representation and use the same technique as described in class/comments to multiply these values and return the result in our representation. int multVals(int source1, int source2) {} Assumptions:To make your life a little easier, we are going to make the following assumptions: No negative numbers. The sign bit can be ignored. No denormalized (or special) numbers. If the given number is too small to be represented as a normalized number, you can return 0. Same thing with numbers that are too large. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
