How to manually (bitwise) perform (float)x?

后端 未结 3 427
一生所求
一生所求 2020-12-01 22:15

Now, here is the function header of the function I\'m supposed to implement:

/*
 * float_from_int - Return bit-level equivalent of expression (float) x
 *            


        
3条回答
  •  萌比男神i
    2020-12-01 22:31

    Dealing with 0x80000000 is pretty easy:

    int xIsNegative = 0;  
    unsigned int absValOfX = x;  
    
    if (x < 0)
    {  
        xIsNegative = 1;  
        absValOfX = -(unsigned int)x;  
    }
    

    It gets rid of special casing -2147483648 since that value is representable as an unsigned value, and absValOfX should always be positive.

提交回复
热议问题