Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Implementing Floating Point Representations in MLKY Scripting Language
Answered

Input

In class, we talked about the IEEE standard for floating point representation and did examples using different sizes for exponent and fraction fields so that you could learn how to do the conversions. For this assignment, you are going to write code to do this, allowing you to convert the floating point numbers to a bit-level representation. You will also write code to perform addition and multiplication of floating point vals

Input: You will read in a script for the MLKY scripting language, which we have implemented and provided to you as the starting code, and call your functions to implement floating point support for these scripts. The MLKY language is very simple with only 4 different kinds of statements: assignment, print, add and multiply. An example of a program is given below:

Output: The output will be the current values of the given variables at the print statements. For the above script, the output would be: 

Some of this task is already done for you. We will provide a program that reads in the given MLKY scripts, saves the values (as integers that encode the corresponding bitlevel representation in our floating-point format) and calls the functions (described next) that you will be implementing. 

Encoding of our smaller Floating Point within a 32-bit int is in this format:

You are going to implement this 15-bit floating point representation, where 5 bits are for the exponent (exp) and 9 are for the fraction (frac). 

Using bit-level operators, you will write the code for the functions (shown below): • Assignment statement (variable = value) – this operation calls your function compute_fp(), which converts from a C float value to our 15-bit mini-float representation (which only uses the 15 lowest of the given 32 bits in an integer). The return value of the function will be the 32-bit integer that encodes the corresponding bit representation. 

Given the number of bits, the rounding you will have to do for this representation may be substantial. In this assignment, we will simply truncate the fraction (i.e., rounds down for positive and up for negative values)

Print statement (print variable) – uses your get_fp() function to convert from our mini-float representation to a regular C float value, and formats/prints it out nicely. Return the converted C float.

a.For Infinity, return the pre-defined float constant INFINITY

b.For Underflows (eg. Denormalized or 0), return 0 float get_fp(int val) {}

 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 converted back into our representation. (i.e., if E1 > E2:Align M2, then M = M1+M2, E=E1, and adjust M & E as needed)

a.For Underflows (eg. Denormalized or 0), return 0

b.Rounding will be through truncation (as with compute_fp)

When implementing this statement, DO NOT convert the numbers back to float, add them directly as C floats, and then convert to the new representation (doing so will not bring any credit).

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. (i.e. M = M1*M2, E=E1+E2, S=S1^S2, and adjust M & E as needed)

a.For Underflows (eg. Denormalized or 0), return 0

b.Rounding will be through truncation (as with compute_fp) When implementing this statement, DO NOT convert the numbers back to floats, multiply them directly as C floats, and then convert to the new representation (doing so will not bring any credit).

support
Whatsapp
callback
sales
sales chat
Whatsapp
callback
sales chat
close