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

Question 1: Write down an function named bitwisedFloatCompare(float number1, flo

ID: 3669244 • Letter: Q

Question

Question 1: 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. Question 2: Write a function named printFloatRepresentation(float number) that will print the floating point representation of a number using the format given below. (Sign bit) exponent in binary (assumed bit).significand For example if the number passed an argument is 71 your programarrow-10x10.png should print (0) 10000101 (1).00011100000000000000000 Similarly if the number passed to the function as argument is -71 the programarrow-10x10.png should print (1) 10000101 (1).00011100000000000000000 The main function and function skeletons for the two functions are given in the attached C course. Complete the two functions mentioned in the question. ? Use the main function provided to test your functions.Question 1: 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. Question 2: Write a function named printFloatRepresentation(float number) that will print the floating point representation of a number using the format given below. (Sign bit) exponent in binary (assumed bit).significand For example if the number passed an argument is 71 your program should print (0) 10000101 (1).00011100000000000000000 Similarly if the number passed to the function as argument is -71 the program should print (1) 10000101 (1).00011100000000000000000 The main function and function skeletons for the two functions are given in the attached C course. Complete the two functions mentioned in the question. ? Use the main function provided to test your functions. /* * FloatingPointRepresentation.c This file should be included into the programarrow-10x10.png and it needs to be done in C programming. */ #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; } /* * FloatingPointRepresentationFunctions.c */ //************************************************************************************/ // // FloatCompare // // Description:Accepts two float numbers and compares them bitwise based // on floating point representations. This function will have // to CONVERTarrow-10x10.png 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 } //***********************************************************************************/ // // printFloatRepresentation // // Description: Prints the argument passed in floating point representation // Preconditions: // Postconditions: // // Calls: N/A // Called by: main // //***********************************************************************************/ void printFloatRepresentation(float number) { // Write a function that prints the floating point representation of a given number }

Explanation / Answer

Hi here i have written example PHP code to allow me to check if one floating point number is equal to, greater than, less than, or not equal to another floating point number.

// a function for comparing two float numbers  

// float 1 - The first number  

// float 2 - The number to compare against the first  

// operator - The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne  

function compareFloatNumbers($float1, $float2, $operator='=')  

{  

    // Check numbers to 5 digits of precision  

    $epsilon = 0.00001;  

      

    $float1 = (float)$float1;  

    $float2 = (float)$float2;  

      

    switch ($operator)  

    {  

        // equal  

        case "=":  

        case "eq":  

        {  

            if (abs($float1 - $float2) < $epsilon) {  

                return true;  

            }  

            break;    

        }  

        // less than  

        case "<":  

        case "lt":  

        {  

            if (abs($float1 - $float2) < $epsilon) {  

                return false;  

            }  

            else  

            {  

                if ($float1 < $float2) {  

                    return true;  

                }  

            }  

            break;    

        }  

        // less than or equal  

        case "<=":  

        case "lte":  

        {  

            if (compareFloatNumbers($float1, $float2, '<') || compareFloatNumbers($float1, $float2, '=')) {  

                return true;  

            }  

            break;    

        }  

        // greater than  

        case ">":  

        case "gt":  

        {  

            if (abs($float1 - $float2) < $epsilon) {  

                return false;  

            }  

            else  

            {  

                if ($float1 > $float2) {  

                    return true;  

                }  

            }  

            break;    

        }  

        // greater than or equal  

        case ">=":  

        case "gte":  

        {  

            if (compareFloatNumbers($float1, $float2, '>') || compareFloatNumbers($float1, $float2, '=')) {  

                return true;  

            }  

            break;    

        }  

        case "<>":  

        case "!=":  

        case "ne":  

        {  

            if (abs($float1 - $float2) > $epsilon) {  

                return true;  

            }  

            break;    

        }  

        default:  

        {  

            die("Unknown operator '".$operator."' in compareFloatNumbers()");     

        }  

    }  

      

    return false;  

}

Simply pass the two numbers you wish to compare, as well as the operator, and the function will return TRUE or FALSE based on if the case is true or not.

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