#define STEP(bitShift)\ if((0x40000000l >> bitShift) + sqrtVal <= val)\ { \ val -= (0x40000000l >> bitShift) + sqrtVal;\ sqrtVal = (sqrtVal >> 1) | (0x40000000l >> bitShift);\ } \ else \ { \ sqrtVal = sqrtVal >> 1;\ } /****************************************************************************** * * Function Name: FixedSqrt * Description: Calculate the square root. * Parameters: int val: input * Return value: int: square root value. * *****************************************************************************/ int FixedSqrt(int val) { int sqrtVal = 0; STEP(0); STEP(2); STEP(4); STEP(6); STEP(8); STEP(10); STEP(12); STEP(14); STEP(16); STEP(18); STEP(20); STEP(22); STEP(24); STEP(26); STEP(28); STEP(30); if (sqrtVal < val) { ++sqrtVal; } return sqrtVal; }