Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 1 Pt. 2: Building Floating-Point Operations 1 Introduction The purpose of this assignment is to become more familiar with the IEEE 754 floating-point standard.

Lab 1 Pt. 2: Building Floating-Point Operations

1 Introduction The purpose of this assignment is to become more familiar with the IEEE 754 floating-point standard. Youll do this by building several arithmetic operations on the bit-level representations of floating-point values. This portion of the lab also aims to improve your ability to work with less fully-defined problems. You may find that you have to ask for clarifications on Piazza; we encourage that you do so with public posts so that other students may benefit from the answers.

2 Logistics This is an individual project. All handins are electronic. Clarifications and corrections will be posted on Piazza.

3 Handout Instructions You can download a skeleton file float.c from CourseSite. You should do all your work in this file. Be wary of altering the main function, as it may interfere with the autograder. The only file you will be modifying and turning in is float.c.

4 The Assignment You are expected to build part of a single-precision floating point unit in software. To achieve this, you are required to do the following: Provide a function unsigned int to float(int i) which converts integer i to the bit-level representation of (float) i. 1 Provide a function unsigned multiply floats(unsigned f1, unsigned f2) which returns the product of bit-level float representations f1 and f2. Provide a function unsigned add floats(unsigned f1, unsigned f2) which returns the sum of bit-level float representations f1 and f2. You may not use any floating-point operations or unions to write these functions. You are required to handle special cases (denormalization, NaN, infinity). If rounding is necessary, follow the default round-to-even convention.

5 Evaluation Your score will be computed based on correctness and style as follows: 40 Correctness points. 5 Style points. Correctness points. Your implementation will be evaluated against a range of test cases. If a function uses illegal operations as outlined in this document, you will receive no credit for associated test cases. Style points. Weve reserved 5 points for a subjective evaluation of the style of your solutions and your commenting. Your solutions should be as clean and straightforward as possible. Your comments should be informative, but they need not be extensive.

6 Handin Instructions Submit your completed float.c file

float.c as follows

#include

#include

#include

/* we use this union in main to pass a float as an unsigned */

union Converter {

unsigned asInt;

float asFloat;

};

void usage(void)

{

printf("Usage: shell [-hvp] ");

printf("-h print this dialogue ");

printf("-i [val] convert val to float ");

printf("-m [val1] [val2] multiply val1 and val2 ");

printf("-a [val1] [val2] add val1 and val2 ");

exit(1);

}

/* int_to_float(int i) should return the bit-level representation

* of [(float) i;]

* You may not use any floating-point operations to solve this problem.

*/

unsigned int_to_float(int i) { //todo

}

/* multiply_floats(unsigned f1, unsigned f2) should return the bit-level

* representation of [f1 * f2] for floating-point values f1 and f2.

* You may not use any floating-point operations to solve this problem.

*/

unsigned multiply_floats(unsigned f1, unsigned f2) {

// TODO

return 0;

}

/* add_floats(unsigned f1, unsigned f2) should return the bit-level

* representation of [f1 + f2] for floating-point values f1 and f2.

* You may not use any floating-point operations to solve this problem.

*/

unsigned add_floats(unsigned f1, unsigned f2) {

// TODO

return 0;

}

/* Be wary of modifying the main method, as

* changes may interfere with the autograder

*/

int main(int argc, char **argv)

{

char c;

unsigned result;

union Converter val1;

union Converter val2;

// parse arguments

c = getopt(argc, argv, "hi:ma");

switch(c)

{

case 'h': /* print help message */

usage();

break;

case 'i': /* do int-to-float conversion */

result = int_to_float(atoi(optarg));

break;

case 'm': /* multiply */

val1.asFloat = atof(argv[2]);

val2.asFloat = atof(argv[3]);

result = multiply_floats(val1.asInt, val2.asInt);

break;

case 'a': /* add */

val1.asFloat = atof(argv[2]);

val2.asFloat = atof(argv[3]);

result = add_floats(val1.asInt, val2.asInt);

break;

default:

usage();

break;

}

// print out result for autograding

printf("%08x ", result);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions