Question: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1 is less than, equal to or greater than
Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1 is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differing bit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1 > number2, return -1 if number2 > number1 and should return 0 if the two numbers are equal. Please note the solution is constrained to be implemented using bitwise comparison of the two numbers.
//************************************************************************************/
//
// FloatCompare
//
// Description:Accepts two float numbers and compares them bitwise based
// on floating point representations. This function will have
// to convert the given numbers into IEEE floating
// representation and then do bitwise comparison
// Preconditions:two input arguments are passed
// Postconditions:Returns 1,-1 or 0 based on the comparison
// 1 if number1>number2
// -1 if number2>number1
// 0 if equal
// Calls: N/A
// Called by: main
//
//***********************************************************************************/
int FloatCompare(float number1,float number2)
{
// Write the function to compare and return the corresponding value
}
Here is the main function for reference:
/*
* FloatingPointRepresentation.c
Please do not return this file or the main function with your homework
*/
#include
int main()
{
float number1;
float number2;
int comparison;
number1=56;
number2=12;
comparison=FloatCompare(number1,number2) ; // Compare two floating point numbers
if (comparison==1)
printf(%f is greater than %f ,number1,number2);
else if (comparison==-1)
printf(%f is greater than %f ,number2,number1);
else if (comparison==0)
printf(Number are equal );
else
printf(Error );
printFloatRepresentation(number1);
printFloatRepresentation(number2);//Print the floating representations of both numbers
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
