1. Engineering
2. Computer Science
3. floating point number representation in c programming you only need...

# Question: floating point number representation in c programming you only need...

###### Question details

Floating Point Number Representation in C programming

You only need to modify the file hw3.c. Following the Bit-Level Floating-Point Coding Rules implement the function with the following prototype:

/* Compute (float)i */

float_bits float_i2f(int i);

For argument i, this function computes the bit-level representation of (float) i.   hw3.h #ifndef HW3_H
#define HW3_H
typedef unsigned float_bits;
float_bits float_i2f(int i);
#endif

driver.c  #include <stdio.h>
#include <stdlib.h>
#include "hw3.h"

typedef union {
unsigned u;
float f;
} uf_union_type;

float u2f(unsigned u) {
uf_union_type a;
a.u = u;
return a.f;
}

unsigned f2u(float f) {
uf_union_type a;
a.f = f;
return a.u;
}

int testOnei2f(int i, int detail) {
float_bits f = float_i2f(i);
if (detail) {
}

if (detail) {
printf("f: sign = %d, exp = 0x%X, frac = 0x%X ", (f>>31) & 1, (f>>23) & 0xff, f&0x7fffff);
}
else {
}

return 0;
}
else {
return 1;
}
}

void testAlli2f() {
int i=0xFFFFFFFF;
int count = 0;
do {
i = i + 1;
// print out status for every 2^28 numbers tested
if ((i&0x0FFFFFFF) == 0) {
printf("Testing numbers between 0x%.8X to 0x%.8X ", i,i+0x0FFFFFFF);
}
if (!testOnei2f(i, 0)) {
count ++;
if (count >= 10) {
printf("Failed 10 tests. Aborting test. ");
break;
}
}
} while (i != 0xffffffff);
if (count == 0) {
printf("Passed all tests for i2f. ");
}
}

int main(int argc, char **argv) {
long input;
if (argc > 1) {
//testing a given integer
input = strtol(argv,NULL,0);
if(!testOnei2f((int)input,1)) {
printf("Failed one test. ");
}
else {
printf("Passed one test for number %d. ", (int)input);
}
}
else {
testAlli2f();
}
return 0;
}

hw3.c #include "hw3.h"
float_bits float_i2f(int i) {
return 0;
}

Could u modify hw3.c please? Thank you.

###### Solution by an expert tutor 