Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have been assigned the task of writing a C function to compute a floating po

ID: 3839090 • Letter: Y

Question

You have been assigned the task of writing a C function to compute a floating point representation of 4^x. You decide that the best way to do this is to directly construct the IEEE single-precision representation of the result. When x is too small, your routine will return 0.0. When x is too large, it will return +. Fill in the blank portions of the code that follows to compute the correct result. Assume the function u2f returns a floating-point value having an identical bit representation as its unsigned argument. Write the u2f function as well, which receives an unsigned value and returns a float.

static float u2f (unsigned u) {

          /* Returns floating-point value with an identical bit representation of its unsigned argument */

          /* We need to create this function as well */

}

float fpwr4 (int x)

{

          /* Result exponent and fraction */

          unsigned exp, frac;

          unsigned u;

          if (x < ________) {

                    /* Too small. Return 0.0 */

                    exp = ________;

                    frac = ________;

          } else if (x < ________) {

                    /* Denormalized result */

                    exp = ________;

                    frac = ________;

          } else if (x < ________) {

                    /* Normalized result. */

                    exp = ________;

                    frac = ________;

          } else

                    /* Too big. Return + */

                    exp = ________;

                    frac = ________;

          }

          /* Pack exp and frac into 32 bits */

          u = exp << 23 | frac;

          /* Return as float */

          return u2f(u)

}

Also I have absolutely no idea why the Chegg website told me that more information was needed. This is all the information the problem gave me.

Explanation / Answer

static float u2f (unsigned u) {

          /* Returns floating-point value with an identical bit representation of its unsigned argument */

          /* We need to create this function as well */

}

float fpwr4 (int x)

{

          /* Result exponent and fraction */

          unsigned exp, frac;

          unsigned u;

          if (x < ________) {

                    /* Too small. Return 0.0 */

                    exp = ________;

                    frac = ________;

          } else if (x < ________) {

                    /* Denormalized result */

                    exp = ________;

                    frac = ________;

          } else if (x < ________) {

                    /* Normalized result. */

                    exp = ________;

                    frac = ________;

          } else

                    /* Too big. Return + */

                    exp = ________;

                    frac = ________;

          }

          /* Pack exp and frac into 32 bits */

          u = exp << 23 | frac;

          /* Return as float */

          return u2f(u)

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote