Question: Working with floatx numbers will require a lot of bit manipulation. The purpose of bitField.c was to provide bit manipulation tools that you can use

Working with floatx numbers will require a lot of bit manipulation. The purpose of bitField.c was to provide bit manipulation tools that you can use in this project.
Create a floatx number from a double-precision floating point value.
For the project, you will need to implement a single function, the `doubleToFloatx` function that takes a double precision floating point input argument, along with the total number of bits and the number of exponent bits for the floatx version of the value. The function needs to return the floatx version of the number.
At a high level, doing the conversion requires several manipulations:
1. Extracting the sign bit from the double value, and inserting it into the floatx value at the correct position.
2. Handle special cases, such as 0.0, infinity, or not-a-number.
3. Extract the biased exponent from the double value. Check to see if the double value is sub-normal. If so, handle it. Check to make sure the floatx exponent won't overflow (or underflow). If so, handle as a special case. If not, re-bias the exponent using the floatx bias (which depends on the number of exponent bits) and write the result to the correct location in the floatx result.
4. Extract the fraction bits from the double value. Determine how many bits are available for the fraction in the floatx value, and truncate or extend the original value, and write the resulting bits to the floatx result.
5. Return the floatx result.
Provided to you: floatx.h and floatx.c
The floatx.h file declares the single floatx function, `doubleToFloatx`, it will be working on for this project. The floatx.h file also contains a typedef statement to define floatx as an unsigned long (64 bit) integer. You should not have to edit floatx.h.
Your main job will be to complete the definition of the `doubleToFloatx` function in floatx.c. This is the function that takes a double precision floating point value, and returns the floatx representation of that value.
testFloatx.c is a program that uses command line arguments to specify 1) the total number of bits, and 2) the number of exponent bits in a floatx format. It then reads standard input, looking for a double precision floating point value. For each floating point value found in standard input:
- the testFloatx program invokes `doubleToFloatx` with the value read from standard input, and the total bits and exponent size specified in the command line arguments.
- prints the original value, the floatx specification, and the floatx value in hexadecimal.
Any non-whitespace characters from standard input that cannot be translated to a double will cause the program to stop.
We will use UNIX redirection to read and write from files Please do not edit the code in testFloatx.c. There is no need to use file I/O functions to read or write files for this project.
## Coding the project
After reading through this readme, decide whether you want to use the bitFields library. If so, follow the instructions above. Then, start working on floatx.c, implementing the `doubleToFloatx` function. Use `make test` to check your results. You can use on-line floating point calculators to figure out what the correct values should be for a float (328) or double (6423) specification, so get those working first.
You will have to manually verify the results for other specifications, such as a 164 floatx specification.
Here is an example of the output produced when your program is coded correctly:
1= floatx(32,8) : 000000003f800000
100= floatx(32,8) : 0000000042c80000
1.3333333= floatx(32,8) : 000000003faaaaaa
1.27563e+45= floatx(32,8) : 000000007f800000
6.23e+22= floatx(32,8) : 00000000655314a2
7.9e-39= floatx(32,8) : 00000000005605fc
3.4028235e+38= floatx(32,8) : 000000007f7fffff
3.4028236e+38= floatx(32,8) : 000000007f7fffff
Input : q not recognized as a double... quitting*
 Working with floatx numbers will require a lot of bit manipulation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!