Rounding issues with bitwise C code
问题 I have to following bitwise code which casts a floating point value (packaged in an int) to an int value. Question: There are rounding issues so it fails in cases where input is 0x80000001 for example. How do I handle this? Here is the code: if(x == 0) return x; unsigned int signBit = 0; unsigned int absX = (unsigned int)x; if (x < 0) { signBit = 0x80000000u; absX = (unsigned int)-x; } unsigned int exponent = 158; while ((absX & 0x80000000) == 0) { exponent--; absX <<= 1; } unsigned int