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

2. (30 pts) In addition to the default IEEE double-precision format (8 bytes, 64

ID: 647430 • Letter: 2

Question

2. (30 pts) In addition to the default IEEE double-precision format (8 bytes, 64 bits) to store floating-point numbers, computer can also store the numbers in half-precision format (2 bytes, 16 bits). Each value is stored in 2 bytes with 1 bit for the sign, 10 bits for the mantissa, and 5 bits for the signed exponent. Determine (show your work) the smallest and largest positive floating-point numbers (in decimal value) as well as the machine epsilon for this half-precision representation. Note that the exponents range from -14 to 15.

Explanation / Answer

#include <ieee754.h>

int fltequls(float a, float b, int sigfigs)
{
    union ieee754_float *pa, *pb;
    unsigned int aexp, bexp;
    float sig_mag;

    if (a == b)
        return 1;
    pa = (union ieee754_float*)&a;
    pb = (union ieee754_float*)&b;
    aexp = pa->ieee.exponent;
    bexp = pb->ieee.exponent;
    if (aexp != bexp || pa->ieee.negative != pb->ieee.negative)
        return 0;
    pa->ieee.exponent = pb->ieee.exponent = IEEE754_FLOAT_BIAS;
    sig_mag = pow(10, -(float)sigfigs);
    if (fabs(a-b) < sig_mag/2)
        return 1;
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote