Reference no: EM131826900
Assignment
For this assignment, you will be creating a Java class that implements floating point Add and Multiply. The layout of your class should look like this:
// your name
public class fp
{
public int add(int a, int b)
{
...
}
public int mul(int a, int b) {
...
}
}
The name of this file should be 'fp.java'. Email this to me by the start of class on the 23rd. I will have a test program that will call these routines with a number of test cases. Your grade for the homework will be based on the percentage of test cases that your code correctly solves.
As you can see, the inputs and outputs of the routines are all integers. However, the bits in these integers follows the IEEE754 standard, so bit 31 is the S field, bits 23 - 30 are the E field, and bits 0 - 22 are the F field. The first thing you will need to do is split these fields out, and when you are done, assemble the result S, E, and F fields back into an integer. You might do something like this:
int aS = (a >> 31) & 1;
int aE = (a >> 23) & 255;
int aF = a & 0x7FFFFF;
Also, to help test your code, recall these numbers in FP format:
int v24_25 = 0x41C20000; // 24.25
int v_1875 = 0xBE400000; // -0.1875
int v5 = 0xC0A00000; // -5.0
Important notes:
1. Your code should not require any extra packages.
2. The book didn't adequately discuss rounding issues, so none of the test cases will require rounding.
3. The book did not accurately discuss denormalized numbers, so the only denormalized number in the test cases will be the value '0'.
4. But the examples will include zero, infinities, and some NaNs. In particular, figure out how to handle inputs that are infinity.