Floating Point Reprsentation:
Allows you to convert the floating point numbers to a bit-level representation.
INPUT: It reads in a ‘program’ and call functions to implement these programs.
The language is very simple with only 4 different kinds of statements:
Print, Add and Multiply.
An example of one possible program might be:
x = 18
print x
y = 4.55
print y
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, the output would be:
x = 18.0000000000
y = 4.5498046875
a = 22.5468750000
z = 81.8906250000
Implemented a 20-bit floating point representation, where 7 bits are for
the exponent (exp) and 12 are for the fraction (frac). Using the bit-level operators,
wrote functions (shown below) to help implement the program statements:
int computeFP(float val) { }
// input: float value to be represented
// output: 32-bit integer that encodes the input float
value in our IEEE-like format
Print statement (print variable) – for this statement, the value of the variable
in our representation will be converted back to a C floating point using this
function and this will be printed.
float getFP(int val) { }
// Using the defined representation, compute
// and return the floating point value
int multVals(int source1, int source2) {}
int addVals(int source1, int source2) {}
If the given number is too small to be
represented as a normalized number, it returns 0. If the number is too
large, returns -1.
Platform: Program coded with C.