Due: Smartsite Fri., 6/5, 11:55 p.m.
Names of Files to Submit: MyFloat.cpp, MyFloat.h, ReadMe.txt
- If you are working in a group ALL members must submit the assignment
- All programs should compile with no warnings when compiled with the -Wall option
- All prompts for input and all output must match my prompts/output. We use a program to grade
your work and tiny differences can cause your work to be marked as a 0.
The best way to avoid being deducted points is to copy the prompt/unchanging portion ofthe outputs into your code. Make sure to get the spaces as well.
- You must also submit a file called ReadMe.txt. Include the names of all partners and any
trouble you had on the assignment
- The input in the examples has been underlined to help you figure out what is input and what is
output
- Submit your work on Smartsite by uploading each file separately. Do not upload any folders or
compressed files such as .rar, .tar, .targz, .zip etc.
- If you have any questions please post them to Piazza
1. For this assignment you will be implementing floating point add and subtract without using the hardwares floating point or double precision add. This will give you a better understanding of how difficult they are to work with and a higher appreciation of the hardware for doing this for you. You will be turning in a file called MyFloat.cpp and its associated header file, MyFloat.h, that implements your own floating point number. This object should support both + and -.
1. You may not use floating point or double precision add in your solution. This means that you should not have the following in your program:
1. float x,y;
2. x + y;
- MyFloat should represent a float using three unsigned integers: sign, exponent, and mantissa.
- MyFloat must have the following private methods defined on it. These functions need to be
implemented using inline assembly.
1. void unpackFloat(float f);
1. Given a float f this function should set sign, exponent, and mantissa to the
appropriate values based on the value of f. 2. float packFloat() const;
1. This function should return the floating point representation of MyFloat 4. MyFloat must have the following public functions defined on it
1. MyFloat operator+(const MyFloat& rhs) const;
- This function should add this to rhs and return the result of the addition
- When adding the two numbers, the maximum amount of precision must be
maintained.
- Before doing the addition you should restore the leading 1. This means that the
mantissa will end up taking 24 bits.
- Since you are adding two 24 bit numbers together the result could take up to 25
bits.
- Be careful when shifting. Since the numbers are 32 bits, the maximum amount
you can shift either left or right is 31. If you try to shift by more than this,
nothing happens.
- Before doing the addition you should restore the leading 1. This means that the
- After doing the addition the number should be returned to its normalized form.
1. When normalizing the number we will truncate it down to the 23 most
significant bits.
2. MyFloat operator-(const MyFloat& rhs) const;
- This function return this rhs.
- The maximum amount of precision must be maintained
1. One thing to watch out for when subtracting (or adding numbers with different signs) is that you may need to borrow. A borrow would occur if the most significant bit that is right shifted out is a 1.
- The number should be returned to normalized form after adding.
- I highly suggest you call + after slightly modifying rhs
3. bool operator==(const float rhs) const;
1. Returns true if this represents the float on the right hand side.
- You have been provided with a main.cpp that will read in arguments from the command line
and then call your function. Your code must be callable from main.cpp
- Arg1 is a floating point number
- Arg2 is either + or
- Arg3 is another floating point number
- You have also been provided with a header file for MyFloat and a partially completed MyFloat.cpp.
1. Feel free to add additional methods but do not remove any.
- Finally you have been provided with a makefile to compile your submission. Your
submission must be compilable by the given makefile.
- Your CPU may use a different rounding scheme than what we are using your floating point
add/subtract may not match float a + b. You shouldnt try to match the computer but should instead match my answers. If you do think I made a mistake though please let me know.
Examples
./fpArithmetic.out 10 +7My Add: 17
./fpArithmetic.out .5 +.5My Add: 1
./fpArithmetic.out 1736217621 + 0.5My Add: 1.73622e+09
./fpArithmetic.out -5 + 5My Add: 0
./fpArithmetic.out 100 - 50My Subtraction: 50
./fpArithmetic.out 10.3 - 5.1My Subtraction: 5.2
Reviews
There are no reviews yet.