Question
The function below (in c) accepts an integer (representing a floating point value) and returns and integer (representing a floating point value). The function multiplies
The function below (in c) accepts an integer (representing a floating point value) and returns and integer (representing a floating point value). The function multiplies the floating point by 2 and also handles the NaN cases. The last return statement actually multiplies the floating point by 2. Can you please show me or explain how "uf + (1<<23)" is equal to mutliplying the floating point by 2? Just confused on that part. Thanks!!
unsigned float_twice(unsigned uf) {
//uf = +-0 case.
if(uf==0 || uf == 0x80000000) return uf;
//NaN case.
if(((uf>>23) & 0xff) == 0xff) return uf;
//Tiny value, but non-zero case.
if(((uf>>23) & 0xff) == 0x00) {
return (uf & (1<<31)) | (uf<<1);
}
//Otherwise, Add 1 to exp value.
return uf + (1<<23);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started