Explanation of Solution
Function definition for “float_le()” function:
The implementation for “float_le()” and “f2u()”function is given below:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for returns the result as an unsigned
unsigned f2u(float xvl)
{
/* Returns the unsigned value by using "*(unsigned*)&x" */
return *(unsigned*)&xvl;
}
//Function definition for float_le function
int float_le(float x, float y)
{
//Compute the unsigned value for "x"
unsigned ux = f2u(x);
//Compute the unsigned value for "y"
unsigned uy = f2u(y);
//Get the sign bits for "x"
unsigned sx = ux >> 31;
//Get the sign bits for "y"
unsigned sy = uy >> 31;
/* Returns the result for float_le() function */
return (ux << 1 == 0 && uy << 1 == 0) ||
(sx && !sy) ||
(!sx && !sy && ux <= uy) ||
(sx && sy && ux >= uy);
}
//Main function
int main(int argc, char* argv[])
{
/* Call function "float_le" with checking value using "assert" function */
assert(float_le(-0, +0));
assert(float_le(+0, -0));
assert(float_le(0, 6));
assert(float_le(-8, 8));
return 0;
}
The given code is used to check whether its first argument in given function is less than or equal to its second argument...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY