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

1) You will develop a library module of C functions which operate on floating po

ID: 3846265 • Letter: 1

Question

1) You will develop a library module of C functions which operate on floating point values using only integer operations. The library module will include the functions listed below:

float get_infinity(); /* Return infinity */

float get_nan(); /* Return not-a-number */

float get_max_normal(); /* Return largest normal */

float get_min_normal(); /* Return smallest normal */

float get_max_denormal(); /* Return largest denormal */

float get_min_denormal(); /* Return smallest denormal */

int is_negative( float ); /* Test if argument is negative */

int is_infinity( float ); /* Test if argument is infinity */

int is_nan( float ); /* Test if argument is not-a-number */

int is_zero( float ); /* Test if argument is zero */

int is_denormal( float ); /* Test if argument is denormal */

float negate( float ); /* Return negation of argument */

float absolute( float ); /* Return absolute value of argument */

The first six functions will return the specified single-precision value (all will be positive). The return value from function get_nan will have a fraction field where each of the bits is a 1. The next five functions will return 0 if the specified condition is false, and 1 if the condition is true. Functions negate and absolute will perform the appropriate operation on the argument and return the result.

Explanation / Answer

return std::numeric_limits<float>::infinity();

}

float get_nan() {

return std::numeric_limits<double>::quiet_NaN();

}

float get_max_normal() {

return std::numeric_limits<float>::max();

}

float get_min_normal(){

  return std::numeric_limits<float>::min();

}

}

}

int is_negative( float a ){

if (a < 0) return 1;

else return 0;

}

int is_infinity( float x ){

return isinf(x);

}

int is_nan( float x ){

return isnan(x);

}

int is_zero( float x ){

if(x == 0.0) return 1;

else return 0;

}

// A number is denormailzed if its value is lesser than even min.

int is_denormal( float flt ){

  if ( flt != 0 && std::fabsf( flt ) < std::numeric_limits<float>::min() ) {

else return 0;

}

float negate( float x ){

return -1*x;

}

float absolute( float x ){

return fabsf(x);

}